OMX_AacEnc_Utils.c revision 0db3b90dbc46ddaa275f66c94c0c963b6cbd535e
1fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/*
3fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * Copyright (C) Texas Instruments - http://www.ti.com/
4fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin *
5fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * This library is free software; you can redistribute it and/or
6fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * modify it under the terms of the GNU Lesser General Public
7fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * License as published by the Free Software Foundation; either
8fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * version 2.1 of the License, or (at your option) any later version.
9fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin *
10fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin *
11fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * This library is distributed in the hope that it will be useful,
12fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * but WITHOUT ANY WARRANTY; without even the implied warranty of
13fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * Lesser General Public License for more details.
15fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin *
16fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin *
17fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * You should have received a copy of the GNU Lesser General Public
18fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * License along with this library; if not, write to the Free Software
19fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin */
21fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* =============================================================================
22fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*             Texas Instruments OMAP (TM) Platform Software
23fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
24fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
25fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*  Use of this software is controlled by the terms and conditions found
26fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*  in the license agreement under which this software has been supplied.
27fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* =========================================================================== */
28fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
29fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @file OMX_AacEnc_Utils.c
30fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
31fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* This file implements OMX Component for AAC encoder that
32fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* is fully compliant with the OMX Audio specification 1.0.
33fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
34fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @path  $(CSLPATH)\
35fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
36fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @rev  1.0
37fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*/
38fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ----------------------------------------------------------------------------
39fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*!
40fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*! Revision History
41fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*! ===================================
42fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*! 13-Dec-2005 mf:  Initial Version. Change required per OMAPSWxxxxxxxxx
43fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*! to provide _________________.
44fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*!
45fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*!
46fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*! 13-Dec-2005 mf:
47fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*! This is newest file
48fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* =========================================================================== */
49fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
50fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
51fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ------compilation control switches -------------------------*/
52fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/****************************************************************
53fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*  INCLUDE FILES
54fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin****************************************************************/
55fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ----- system and platform files ----------------------------*/
56fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef UNDER_CE
57fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <windows.h>
58fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <oaf_osal.h>
59fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <omx_core.h>
60fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <stdlib.h>
61fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#else
62fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <wchar.h>
63fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <unistd.h>
64fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <sys/types.h>
65fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <sys/wait.h>
66fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <sys/types.h>
67fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <sys/stat.h>
68fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <dlfcn.h>
69fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <malloc.h>
70fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <memory.h>
71fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <fcntl.h>
72fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <errno.h>
73fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <dlfcn.h>
74fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
75fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <dbapi.h>
76fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <string.h>
77fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <stdio.h>
78fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include "OMX_AacEnc_Utils.h"
79fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include "Aacencsocket_ti.h"
80fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <encode_common_ti.h>
81fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include "OMX_AacEnc_CompThread.h"
82fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include "usn.h"
83fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef RESOURCE_MANAGER_ENABLED
84fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#include <ResourceManagerProxyAPI.h>
85fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
86fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
87fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef UNDER_CE
88fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#define HASHINGENABLE 1
89fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
90fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
91fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
92fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
93fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @AACENCFill_LCMLInitParams () This function is used by the component thread to
94fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* fill the all of its initialization parameters, buffer deatils  etc
95fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* to LCML structure,
96fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
97fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pComponent  handle for this instance of the component
98fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param plcml_Init  pointer to LCML structure to be filled
99fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
100fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @pre
101fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
102fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @post
103fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
104fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @return none
105fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*/
106fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
107fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/*static AACENC_COMPONENT_PRIVATE *pComponentPrivate_CC;*/
108fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
109fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_ERRORTYPE AACENCFill_LCMLInitParams(OMX_HANDLETYPE pComponent, LCML_DSP *plcml_Init, OMX_U16 arr[])
110fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
111fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
112fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 nIpBuf =0 ,nIpBufSize=0 ,nOpBuf = 0 ,nOpBufSize=0;
113fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 i                               = 0;
114fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_BUFFERHEADERTYPE *pTemp             = NULL;
115fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_S32 size_lcml                       = 0;
116fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    char *ptr;
117fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_AACENC_BUFHEADERTYPE *pTemp_lcml   = NULL;
118fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
119fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin     AACENC_COMPONENT_PRIVATE *pComponentPrivate = pHandle->pComponentPrivate;
120fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_STRMATTR *strmAttr                 = NULL;
121fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U16 HigherBitsSamplingRate          = 0;
122fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U16 FramesPerOutBuf                 = 0;
123fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U16 Channels                        = 0;
124fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
125b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin
126b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: AACENCFill_LCMLInitParams\n ",__LINE__);
127fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
128fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->nRuntimeInputBuffers = nIpBuf;
129fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nIpBufSize = pComponentPrivate->pPortDef[INPUT_PORT]->nBufferSize;
130fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
131fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nOpBufSize = pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferSize;
132fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /*saving a copy a number of output buffers */
133fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->nRuntimeOutputBuffers = nOpBuf;
134fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
135fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /*recovering the value for the number of frames per Ouput Buffer */
136fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    FramesPerOutBuf = (OMX_U16)pComponentPrivate->FramesPer_OutputBuffer;
137b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: Frames per output buffer = %d \n\n",__LINE__, FramesPerOutBuf);
138fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
139fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
140b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: ------ Buffer Details -----------\n",__LINE__);
141b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Input  Buffer Count = %ld \n",__LINE__,nIpBuf);
142b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Input  Buffer Size = %ld\n",__LINE__,nIpBufSize);
143b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Output Buffer Count = %ld\n",__LINE__,nOpBuf);
144b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Output Buffer Size = %ld\n",__LINE__,nOpBufSize);
145b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: ------ Buffer Details ------------\n",__LINE__);
146fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
147fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /* Fill Input Buffers Info for LCML */
148fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->In_BufInfo.nBuffers = nIpBuf;
149fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->In_BufInfo.nSize = nIpBufSize;
150fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->In_BufInfo.DataTrMethod = DMM_METHOD;
151fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
152fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /* Fill Output Buffers Info for LCML */
153fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->Out_BufInfo.nBuffers = nOpBuf;
154fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->Out_BufInfo.nSize = nOpBufSize;
155fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->Out_BufInfo.DataTrMethod = DMM_METHOD;
156fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
157fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /*Copy the node information*/
158fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->NodeInfo.nNumOfDLLs = 3;
159fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
160fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->NodeInfo.AllUUIDs[0].uuid = (struct DSP_UUID*)&MPEG4AACENC_SN_UUID;
161fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[0].DllName,AACENC_DLL_NAME);
162fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT;
163fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
164fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
165fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->NodeInfo.AllUUIDs[1].uuid = (struct DSP_UUID*)&MPEG4AACENC_SN_UUID;
166fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[1].DllName,AACENC_DLL_NAME);
167fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT;
168fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
169fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
170fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->NodeInfo.AllUUIDs[2].uuid = &USN_TI_UUID;
171fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[2].DllName,AACENC_USN_DLL_NAME);
172fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT;
173fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
174fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->DeviceInfo.TypeofDevice = 0;
175b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_AacEncUtils.c\n",__LINE__);
176fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if(pComponentPrivate->dasfmode == 1) {
177b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Codec is configuring to DASF mode\n",__LINE__);
178b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_MALLOC_GENERIC(strmAttr, LCML_STRMATTR);
179b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRINT1(pComponentPrivate->dbg, "strmAttr %p \n",strmAttr);
180fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
181fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate->strmAttr = strmAttr;
182b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: [ALLOC] %p\n",__LINE__,strmAttr);
183fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        strmAttr->uSegid        = 0;
184fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        strmAttr->uAlignment    = 0;
185fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        strmAttr->uTimeout      = 1000;
186fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        strmAttr->uBufsize      = INPUT_AACENC_BUFFER_SIZE_DASF;
187fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        strmAttr->uNumBufs      = NUM_AACENC_INPUT_BUFFERS_DASF;
188fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        strmAttr->lMode         = STRMMODE_PROCCOPY;
189fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
190fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        plcml_Init->DeviceInfo.TypeofDevice = 1;
191fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        plcml_Init->DeviceInfo.TypeofRender = 1;
192fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &DCTN_TI_UUID;
193fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        plcml_Init->DeviceInfo.DspStream = strmAttr;
194fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
195fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
196fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /*copy the other information*/
197fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->SegID       = OMX_AACENC_DEFAULT_SEGMENT;
198fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->Timeout     = -1;/*OMX_AACENC_SN_TIMEOUT;*/
199fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->Alignment   = 0;
200fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->Priority    = OMX_AACENC_SN_PRIORITY;
201fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->ProfileID   = -1;
202fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
203fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->unNumChannels   = (OMX_U16)pComponentPrivate->aacParams[OUTPUT_PORT]->nChannels;       /*Number of Channels*/
204fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /* splitting values for Sample rate and bit rate */
205fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->ulSamplingRate  = (OMX_U16)pComponentPrivate->aacParams[OUTPUT_PORT]->nSampleRate;       /*Sampling rate*/
206fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    HigherBitsSamplingRate             =(OMX_U16)((pComponentPrivate->aacParams[OUTPUT_PORT]->nSampleRate >>16)& 0xFFFF);
207fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->unBitrate       = pComponentPrivate->aacParams[OUTPUT_PORT]->nBitRate;                /*Bit rate 2bytes*/
208fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->nObjectType     = pComponentPrivate->aacParams[OUTPUT_PORT]->eAACProfile;            /*Object Type */
209fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
210fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /*   Remaping Number of channels for SN */
211fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /*   SN does use 0: Mono and  1: stereo      */
212fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if(pComponentPrivate->unNumChannels==2)
213fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
214fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        Channels=1;
215fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
216fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (pComponentPrivate->unNumChannels==1)
217fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
218fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        Channels=0;
219fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
220fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
221fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (pComponentPrivate->aacParams[OUTPUT_PORT]->eAACStreamFormat == OMX_AUDIO_AACStreamFormatRAW ||
222fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate->aacParams[OUTPUT_PORT]->eAACStreamFormat == OMX_AUDIO_AACStreamFormatMP4FF){
223fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate->File_Format = 0;
224b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_AUDIO_AACStreamFormatRAW \n");
225fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
226fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (pComponentPrivate->aacParams[OUTPUT_PORT]->eAACStreamFormat == OMX_AUDIO_AACStreamFormatADIF) {
227fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate->File_Format = 1;
228b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_AUDIO_AACStreamFormatADIF \n");
229fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
230fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if((pComponentPrivate->aacParams[OUTPUT_PORT]->eAACStreamFormat == OMX_AUDIO_AACStreamFormatMP4ADTS) ||
231fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            (pComponentPrivate->aacParams[OUTPUT_PORT]->eAACStreamFormat == OMX_AUDIO_AACStreamFormatMP2ADTS) )
232fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
233fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate->File_Format = 2;
234b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_AUDIO_AACStreamFormatMP2ADTS \n");
235fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
236fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
237fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if(pComponentPrivate->dasfmode == 1) {
238b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AAC ENCODER RUNNING UNDER DASF MODE\n",__LINE__);
239fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
240fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[0]  = 2;                                                      /*Number of Streams*/
241fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[1]  = 0;                                                      /*ID of the Input Stream*/
242fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[2]  = 1;                                                      /*Type of Input Stream*/
243fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[3]  = NUM_AACENC_INPUT_BUFFERS_DASF;                          /*Number of buffers for Input Stream*/
244fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[4]  = 1;                                                      /*ID of the Output Stream*/
245fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[5]  = 0;                                                      /*Type of Output Stream*/
246fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[6]  = 2;                                                      /*Number of buffers for Output Stream*/
247fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[7]  = 1;                                                      /*PNS Enable*/
248fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[8]  = 1;                                                      /*TNS Enable*/
249fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[9]  = Channels;                                               /*Number of Channels*/
250fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[10] = pComponentPrivate->ulSamplingRate;                      /*Sampling rate- Lower bits*/
251fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[11] = HigherBitsSamplingRate;                                 /*Sampling rate -Higher bits */
252fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[12] = (OMX_U16)(pComponentPrivate->unBitrate & 0xFFFF);       /*Bit rate 2bytes*/
253fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[13] = (OMX_U16)(pComponentPrivate->unBitrate >> 16);          /*Bit rate 2bytes*/
254fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[14] = (OMX_U16)pComponentPrivate->nObjectType;                /*Object Type */
255fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[15] = (OMX_U16)pComponentPrivate->bitRateMode;                /*bitrateMode*/
256fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[16] = (OMX_U16)pComponentPrivate->File_Format;                /*FileFormat*/
257fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[17] = FramesPerOutBuf;                                        /*FramesPerOutBuf*/
258fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[18] = END_OF_CR_PHASE_ARGS;
259fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
260fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
261fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
262fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if(pComponentPrivate->dasfmode == 0) {
263b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AAC ENCODER RUNNING UNDER FILE MODE\n",__LINE__);
264fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[0]  = 2;                                                      /*Number of Streams*/
265fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[1]  = 0;                                                      /*ID of the Input Stream*/
266fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[2]  = 0;                                                      /*Type of Input Stream*/
267fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if (pComponentPrivate->pInputBufferList->numBuffers) {
268fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            arr[3] = (OMX_U16) pComponentPrivate->pInputBufferList->numBuffers;     /*Number of buffers for Input Stream*/
269b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER1(pComponentPrivate->dbg, "arr[3] InputBuffers %d \n",arr[3]);
270fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
271fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        else {
272fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            arr[3] = 1;
273fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
274fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[4]  = 1;                                                      /*ID of the Output Stream*/
275fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[5]  = 0;                                                      /*Type of Output Stream*/
276fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if (pComponentPrivate->pOutputBufferList->numBuffers) {
277fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            arr[6] = (OMX_U16) pComponentPrivate->pOutputBufferList->numBuffers;    /*Number of buffers for Output Stream*/
278b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER1(pComponentPrivate->dbg, "arr[6] Output Buffers%d \n",arr[6]);
279fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
280fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        else {
281fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            arr[6] = 1;
282fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
283fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
284fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[7]  = 1;                                                      /*PNS Enable*/
285fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[8]  = 1;                                                      /*TNS Enable*/
286fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        /*  Adjusting the value for SN enum-type compatibility */
287fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[9]  = Channels;                                               /*Number of Channels*/
288b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRCOMM2(pComponentPrivate->dbg, "arr[9] Channels %d \n",arr[9]);
289fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[10] = pComponentPrivate->ulSamplingRate;                      /*Sampling rate- Lower bits*/
290fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[11] = HigherBitsSamplingRate;                                 /*Sampling rate -Higher bits */
291fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[12] = (OMX_U16)(pComponentPrivate->unBitrate & 0xFFFF);       /*Bit rate 2bytes*/
292fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[13] = (OMX_U16)(pComponentPrivate->unBitrate >> 16);          /*Bit rate 2bytes*/
293fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[14] = (OMX_U16)pComponentPrivate->nObjectType;                                        /*bitsperSample;*/
294b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT2(pComponentPrivate->dbg, "arr[14] Object Type %d \n",arr[14]);
295fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[15] = (OMX_U16)pComponentPrivate->bitRateMode;                /*bitrateMode*/
296b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT2(pComponentPrivate->dbg, "arr[15] Bit Rate %d \n",arr[15]);
297fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[16] = pComponentPrivate->File_Format;                         /*FileFormat*/
298b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT2(pComponentPrivate->dbg, "arr[16] format type %d \n",arr[16]);
299fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[17] = FramesPerOutBuf;                                        /*FramesPerOutBuf*/
300fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        arr[18] = END_OF_CR_PHASE_ARGS;
301fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
302fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
303fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
304fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    plcml_Init->pCrPhArgs = arr;
305fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
306b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_AacEncUtils.c\n",__LINE__);
307fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    size_lcml = nIpBuf * sizeof(LCML_AACENC_BUFHEADERTYPE);
308b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    OMX_MALLOC_SIZE(ptr, size_lcml,char);
309fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pTemp_lcml = (LCML_AACENC_BUFHEADERTYPE *)ptr;
310fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->pLcmlBufHeader[INPUT_PORT] = pTemp_lcml;
311fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    for (i=0; i<nIpBuf; i++)
312fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
313fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i];
314fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
315fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nAllocLen = nIpBufSize;
316fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nFilledLen = nIpBufSize;
317fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nVersion.s.nVersionMajor = AACENC_MAJOR_VER;
318fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nVersion.s.nVersionMinor = AACENC_MINOR_VER;
319fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
320fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nTickCount = NOT_USED;
321fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml->buffer = pTemp;
322fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml->eDir = OMX_DirInput;
323fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
324b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam,
325b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                               sizeof(AACENC_UAlgInBufParamStruct),
326b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                               AACENC_UAlgInBufParamStruct);
327b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP2(pComponentPrivate->dbg, "pTemp_lcml->pIpParam %p \n",pTemp_lcml->pIpParam);
328fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
329fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml->pIpParam->bLastBuffer = 0;
330fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        /* This means, it is not a last buffer. This flag is to be modified by
331fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                * the application to indicate the last buffer */
332fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nFlags = NORMAL_BUFFER;
333fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml++;
334fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
335fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
336fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /* Allocate memory for all output buffer headers,  This memory pointer will be sent to LCML */
337fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    size_lcml = nOpBuf * sizeof(LCML_AACENC_BUFHEADERTYPE);
338fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
339b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    OMX_MALLOC_SIZE(ptr, size_lcml,char);
340fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pTemp_lcml = (LCML_AACENC_BUFHEADERTYPE *)ptr;
341fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
342fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT] = pTemp_lcml;
343fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    for (i=0; i<nOpBuf; i++)
344fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
345fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
346fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
347fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nAllocLen = nOpBufSize;
348fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nFilledLen = nOpBufSize;
349fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nVersion.s.nVersionMajor = AACENC_MAJOR_VER;
350fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nVersion.s.nVersionMinor = AACENC_MINOR_VER;
351fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate->nVersion = pTemp->nVersion.nVersion;
352fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
353fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nTickCount = NOT_USED;
354fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        /* This means, it is not a last buffer. This flag is to be modified by
355fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    the application to indicate the last buffer */
356fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml->buffer = pTemp;
357fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml->eDir = OMX_DirOutput;
358fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        /* SN : Each output buffer may be accompanied by an output buffer parameters structure*/
359fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
360b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pOpParam,
361b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                               sizeof(AACENC_UAlgOutBufParamStruct),
362b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                               AACENC_UAlgOutBufParamStruct);
363fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
364b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP1(pComponentPrivate->dbg, "%d :: UTIL: size of pOpParam: %d \n",__LINE__,sizeof(pTemp_lcml->pOpParam->unFrameSizes));
365b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP1(pComponentPrivate->dbg, "%d :: UTIL: numframes of pOpParam: %d \n\n",__LINE__,sizeof(pTemp_lcml->pOpParam->unNumFramesEncoded)) ;
366b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP1(pComponentPrivate->dbg, "UTIL: pTemp_lcml->pOpParam %p \n",pTemp_lcml->pOpParam);
367fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
368fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nFlags = NORMAL_BUFFER;
369fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        /*pTemp++;*/
370fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml++;
371fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
372fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bPortDefsAllocated = 1;
373fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bBypassDSP = 0;
374fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bNoIdleOnStop= OMX_FALSE;
375fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
376fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
377b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->ptAlgDynParams,
378b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                sizeof(MPEG4AACENC_UALGParams),
379fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                MPEG4AACENC_UALGParams);
380fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
381b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT2(pComponentPrivate->dbg, "UTIL: pComponentPrivate->ptAlgDynParams %p \n",pComponentPrivate->ptAlgDynParams);
382fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
383fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
384fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate->nLcml_nCntIp = 0;
385fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate->nLcml_nCntOpReceived = 0;
386fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
387fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
388fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
389fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinEXIT:
390b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Exiting Fill_LCMLInitParams\n",__LINE__);
391b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Returning = 0x%x\n",__LINE__,eError);
392fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return eError;
393fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
394fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
395fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
396fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
397fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* AACENC_StartComponentThread() This function is called by the component to create
398fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* the component thread, command pipe, data pipe and LCML Pipe.
399fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
400fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pComponent  handle for this instance of the component
401fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
402fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @pre
403fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
404fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @post
405fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
406fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @return none
407fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*/
408fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
409fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
410fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_ERRORTYPE AACENC_StartComponentThread(OMX_HANDLETYPE pComponent)
411fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
412fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
413fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
414fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
415fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef UNDER_CE
416fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pthread_attr_t attr;
417fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    memset(&attr, 0, sizeof(attr));
418fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    attr.__inheritsched = PTHREAD_EXPLICIT_SCHED;
419fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    attr.__schedparam.__sched_priority = OMX_AUDIO_DECODER_THREAD_PRIORITY;
420fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
421fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
422fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
423b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering  AACENC_StartComponentThread\n", __LINE__);
424fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /* Initialize all the variables*/
425fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bIsStopping = 0;
426fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bIsThreadstop = 0;
427fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->lcml_nOpBuf = 0;
428fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->lcml_nIpBuf = 0;         /* Initializing counter */
429fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->app_nBuf = 0;                    /* Not Used */
430fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->num_Op_Issued = 0;
431fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->num_Sent_Ip_Buff = 0;
432fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->num_Reclaimed_Op_Buff = 0;       /* Not Used */
433fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bIsEOFSent = 0;
434fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
435fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /* create the pipe used to send buffers to the thread */
436fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    eError = pipe (pComponentPrivate->cmdDataPipe);
437fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (eError)
438fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
439b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Inside  AACENC_StartComponentThread\n", __LINE__);
440fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        eError = OMX_ErrorInsufficientResources;
441fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
442fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
443fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
444fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /* create the pipe used to send buffers to the thread */
445fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    eError = pipe (pComponentPrivate->dataPipe);
446fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (eError)
447fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
448b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Inside  AACENC_StartComponentThread\n", __LINE__);
449fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        eError = OMX_ErrorInsufficientResources;
450fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
451fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
452fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
453fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /* create the pipe used to send commands to the thread */
454fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    eError = pipe (pComponentPrivate->cmdPipe);
455fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (eError) {
456b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Inside  AACENC_StartComponentThread\n", __LINE__);
457fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        eError = OMX_ErrorInsufficientResources;
458fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
459fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
460fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
461fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /* create the pipe used to send commands to the thread */
462fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef UNDER_CE
463b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    eError = pthread_create (&(pComponentPrivate->ComponentThread), &attr, AACENC_ComponentThread, pComponentPrivate);
464fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#else
465b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    eError = pthread_create (&(pComponentPrivate->ComponentThread), NULL, AACENC_ComponentThread, pComponentPrivate);
466fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
467fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (eError || !pComponentPrivate->ComponentThread) {
468b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Inside  AACENC_StartComponentThread\n", __LINE__);
469fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        eError = OMX_ErrorInsufficientResources;
470fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
471fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
472fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
473b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRDSP1(pComponentPrivate->dbg, "%d :: pComponent[%x] AACENC_StartComponentThread\n", __LINE__, (int)pComponent) ;
474b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRDSP1(pComponentPrivate->dbg, "%d :: pHandle[%x] AACENC_StartComponentThread\n", __LINE__, (int)pHandle) ;
475fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bCompThreadStarted = 1;
476fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
477fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinEXIT:
478b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting from AACENC_StartComponentThread\n", __LINE__);
479b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
480fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return eError;
481fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
482fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
483fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
484fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
485fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* AACENC_FreeCompResources() This function is called by the component during
486fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* de-init to close component thread, Command pipe, data pipe & LCML pipe.
487fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
488fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pComponent  handle for this instance of the component
489fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
490fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @pre
491fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
492fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @post
493fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
494fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @return none
495fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*/
496fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
497fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
498fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_ERRORTYPE AACENC_FreeCompResources(OMX_HANDLETYPE pComponent)
499fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
500fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
501fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
502fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
503fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
504fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE err = OMX_ErrorNone;
505fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 nIpBuf = 0;
506fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 nOpBuf = 0;
507fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
508b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, " %d :: Entering AACENC_FreeCompResources\n",__LINE__);
509fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (pComponentPrivate->bPortDefsAllocated) {
510fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        nIpBuf = pComponentPrivate->pPortDef[INPUT_PORT]->nBufferCountActual;
511fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        nOpBuf = pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferCountActual;
512fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
513fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
514fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (pComponentPrivate->bCompThreadStarted) {
515fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        OMX_CLOSE_PIPE(pComponentPrivate->dataPipe[0],err);
516fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        OMX_CLOSE_PIPE(pComponentPrivate->dataPipe[1],err);
517fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        OMX_CLOSE_PIPE(pComponentPrivate->cmdPipe[0],err);
518fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        OMX_CLOSE_PIPE(pComponentPrivate->cmdPipe[1],err);
519fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        OMX_CLOSE_PIPE(pComponentPrivate->cmdDataPipe[0],err);
520fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        OMX_CLOSE_PIPE(pComponentPrivate->cmdDataPipe[1],err);
521fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
522fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
523fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (pComponentPrivate->bPortDefsAllocated) {
524fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[INPUT_PORT]);
525fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[OUTPUT_PORT]);
526fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        OMX_MEMFREE_STRUCT(pComponentPrivate->aacParams[INPUT_PORT]);
527fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        OMX_MEMFREE_STRUCT(pComponentPrivate->aacParams[OUTPUT_PORT]);
528fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        OMX_MEMFREE_STRUCT(pComponentPrivate->pcmParam[INPUT_PORT]);
529fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        OMX_MEMFREE_STRUCT(pComponentPrivate->pcmParam[OUTPUT_PORT]);
530fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
531fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bPortDefsAllocated = 0;
532fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
533fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifndef UNDER_CE
534b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRDSP1(pComponentPrivate->dbg, "\n\n FreeCompResources: Destroying mutexes.\n\n");
535fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pthread_mutex_destroy(&pComponentPrivate->InLoaded_mutex);
536fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pthread_cond_destroy(&pComponentPrivate->InLoaded_threshold);
537fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
538fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pthread_mutex_destroy(&pComponentPrivate->InIdle_mutex);
539fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pthread_cond_destroy(&pComponentPrivate->InIdle_threshold);
540fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
541fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pthread_mutex_destroy(&pComponentPrivate->AlloBuf_mutex);
542fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pthread_cond_destroy(&pComponentPrivate->AlloBuf_threshold);
5430db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong
5440db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong    pthread_mutex_destroy(&bufferReturned_mutex);
5450db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong    pthread_cond_destroy(&bufferReturned_condition);
546fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#else
547fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bPortDefsAllocated = 0;
548fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_DestroyEvent(&(pComponentPrivate->InLoaded_event));
549fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_DestroyEvent(&(pComponentPrivate->InIdle_event));
550fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_DestroyEvent(&(pComponentPrivate->AlloBuf_event));
551fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
552fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
553fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinEXIT:
554b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting AACENC_FreeCompResources()\n",__LINE__);
555b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
556fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
557fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return eError;
558fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
559fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
560fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
561fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
562fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @AACENC_CleanupInitParams() This function is called by the component during
563fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* de-init to free structues that are been allocated at intialization stage
564fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
565fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pComponent  handle for this instance of the component
566fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
567fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @pre
568fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
569fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @post
570fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
571fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @return none
572fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*/
573fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
574fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_ERRORTYPE AACENC_CleanupInitParams(OMX_HANDLETYPE pComponent)
575fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
576fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
577fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
578fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_AACENC_BUFHEADERTYPE *pTemp_lcml=NULL;
579fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
580fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 nIpBuf = 0;
581fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 nOpBuf = 0;
582fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 i      = 0;
583fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
584b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering AACENC_CleanupInitParams()\n", __LINE__);
585fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr);
586fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
587fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pTemp_lcml = pComponentPrivate->pLcmlBufHeader[INPUT_PORT];
588fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
589fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    for(i=0; i<nIpBuf; i++)
590fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
591b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pIpParam, AACENC_UAlgInBufParamStruct);
592fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml++;
593fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
594fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
595fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /*Free ouput buffers params */
596fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pTemp_lcml = pComponentPrivate->pLcmlBufHeader[OUTPUT_BUFFER];
597fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nOpBuf = pComponentPrivate->nRuntimeOutputBuffers;
598fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    for (i=0; i<nOpBuf; i++)
599fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
600b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pOpParam, AACENC_UAlgOutBufParamStruct);
601fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml++;
602fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
603fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
604fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[INPUT_PORT]);
605fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT]);
606b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->ptAlgDynParams, MPEG4AACENC_UALGParams);
607fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if(pComponentPrivate->dasfmode == 1)
608fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
609b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, AACENC_AudioCodecParams);
610fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
611fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
612b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting Successfully AACENC_CleanupInitParams()\n",__LINE__);
613b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
614fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return eError;
615fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
616fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
617fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
618fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
619fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* AACENC_StopComponentThread() This function is called by the component during
620fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* de-init to close component thread, Command pipe, data pipe & LCML pipe.
621fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
622fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pComponent  handle for this instance of the component
623fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
624fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @pre
625fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
626fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @post
627fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
628fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @return none
629fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*/
630fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
631fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
632fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_ERRORTYPE AACENC_StopComponentThread(OMX_HANDLETYPE pComponent)
633fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
634fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
635fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
636fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
637fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
638fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE threadError = OMX_ErrorNone;
639fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    int pthreadError = 0;
640fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
641b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, " %d :: UTIL: Entering AACENC_StopComponentThread\n",__LINE__);
642fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /*Join the component thread*/
643fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bIsThreadstop = 1;
644fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    write (pComponentPrivate->cmdPipe[1], &pComponentPrivate->bIsThreadstop, sizeof(OMX_U16));
645b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRSTATE1(pComponentPrivate->dbg, "UTIL: pComponentPrivate->bIsThreadstop = %ld \n",pComponentPrivate->bIsThreadstop);
646fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pthreadError = pthread_join (pComponentPrivate->ComponentThread,(void*)&threadError);
647fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (0 != pthreadError)
648fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
649fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        eError = OMX_ErrorHardware;
650b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error closing ComponentThread - pthreadError = %d\n",__LINE__,pthreadError);
651fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
652fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
653fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
654fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /*Check for the errors*/
655fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (OMX_ErrorNone != threadError && OMX_ErrorNone != eError)
656fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
657fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        eError = OMX_ErrorInsufficientResources;
658b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error while closing Component Thread\n",__LINE__);
659fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
660fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
661fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
662fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinEXIT:
663b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, " %d :: UTIL: Exiting AACENC_StopComponentThread\n",__LINE__);
664fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return eError;
665fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
666fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
667fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
668fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
669fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
670fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* AACENCHandleCommand() This function is called by the component when ever it
671fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* receives the command from the application
672fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
673fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pComponentPrivate  Component private data
674fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
675fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @pre
676fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
677fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @post
678fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
679fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @return none
680fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*/
681fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
682fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
683fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_U32 AACENCHandleCommand(AACENC_COMPONENT_PRIVATE *pComponentPrivate)
684fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
685fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
686fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
687fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_COMMANDTYPE command;
688fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_STATETYPE commandedState;
689fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 commandData;
690fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_HANDLETYPE pLcmlHandle = pComponentPrivate->pLcmlHandle;
691fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE rm_error = OMX_ErrorNone;
692fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
693fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U16 arr[100]={0};
694fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_S32 ret = 0;
695fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 i=0;
696fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    char *p  = "start";
697fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    char *pArgs = "damedesuStr";
698fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 pValues[4]={0};
699fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 pValues1[4]={0};
700fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_CALLBACKTYPE cb;
701fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_DSP *pLcmlDsp = NULL;
702fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_AACENC_BUFHEADERTYPE *pLcmlHdr;
703fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    int inputPortFlag = 0;
704fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    int outputPortFlag = 0;
705fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
706b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: AACENC: Entering AACENCHandleCommand Function - curState = %d\n",__LINE__,pComponentPrivate->curState);
707fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    ret = read (pComponentPrivate->cmdPipe[0], &command, sizeof (command));
708b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_TRACE1(pComponentPrivate->dbg, "%d :: AACENC: Command pipe has been read = %ld \n",__LINE__,ret);
709fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (ret == -1)
710fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
711b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error in Reading from the Data pipe\n", __LINE__);
712fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        eError = OMX_ErrorHardware;
713fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
714fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
715fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    ret = read (pComponentPrivate->cmdDataPipe[0], &commandData, sizeof (commandData));
716b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_TRACE1(pComponentPrivate->dbg, "%d :: AACENC: Command data pipe has been read = %ld \n",__LINE__,ret);
717fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (ret == -1)
718fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
719b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error in Reading from the Data pipe\n", __LINE__);
720fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        eError = OMX_ErrorHardware;
721fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
722fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
723fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
724fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
725fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    PERF_ReceivedCommand(pComponentPrivate->pPERFcomp,command,commandData,PERF_ModuleLLMM);
726fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
727fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
728b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENCHandleCommand :: Command is = %d\n",__LINE__,command);
729fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (command == OMX_CommandStateSet)
730fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
731fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        commandedState = (OMX_STATETYPE)commandData;
732fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if ( pComponentPrivate->curState==commandedState)
733fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
734fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->cbInfo.EventHandler(pHandle,
735fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                   pHandle->pApplicationPrivate,
736fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                   OMX_EventError,
737fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                   OMX_ErrorSameState,
738fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                   OMX_TI_ErrorMinor,
739fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                   NULL);
740b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Same State Given by Application\n",__LINE__);
741b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_ERROR4(pComponentPrivate->dbg, "%d :: AACENC: State Given is: %d \n", __LINE__, commandedState);
742fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
743fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        else
744fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
745fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            switch(commandedState)
746fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
747fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                case OMX_StateIdle:
748b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                    OMX_PRDSP2(pComponentPrivate->dbg, "%d: AACENCHandleCommand: Cmd Idle \n",__LINE__);
749b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                    OMX_PRDSP2(pComponentPrivate->dbg, "AACENC: curstate = %d\n",pComponentPrivate->curState);
750fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    if (pComponentPrivate->curState == OMX_StateLoaded)
751fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
752fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
753fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
754fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySetup);
755fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
756fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if(pComponentPrivate->dasfmode == 1)
757fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
758fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            if (pComponentPrivate->dasfmode == 1)
759fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            {
760fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled= FALSE;
761fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated= FALSE;
762fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            }
763fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            if (pComponentPrivate->streamID==0)
764fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            {
765fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
766b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                                OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Insufficient resources\n", __LINE__);
767fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                eError = OMX_ErrorInsufficientResources;
768b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                                OMX_ERROR4(pComponentPrivate->dbg, "AACENC: State changed to OMX_StateInvalid Line %d\n",__LINE__);
769fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                pComponentPrivate->curState = OMX_StateInvalid;
770fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                pComponentPrivate->cbInfo.EventHandler(pHandle,
771fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                        pHandle->pApplicationPrivate,
772fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                        OMX_EventError,
773fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                        eError,
774fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                        OMX_TI_ErrorMajor,
775fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                        "No Stream ID Available");
776fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                goto EXIT;
777fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            }
778fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
779fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
780b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_StateLoaded [INPUT_PORT]->bPopulated  %d \n",__LINE__,pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated);
781b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_StateLoaded [INPUT_PORT]->bEnabled    %d \n",__LINE__,pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled);
782b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_StateLoaded [OUTPUT_PORT]->bPopulated %d \n",__LINE__,pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated);
783b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_StateLoaded [OUTPUT_PORT]->bEnabled   %d \n",__LINE__,pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled);
784fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
785fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated &&  pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled)  {
786fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            inputPortFlag = 1;
787fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
788fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
789fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (!pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated && !pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled) {
790fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            inputPortFlag = 1;
791fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
792fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
793fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated && pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled) {
794fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            outputPortFlag = 1;
795fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
796fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
797fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (!pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated && !pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled) {
798fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            outputPortFlag = 1;
799fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
800fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
801b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRCOMM2(pComponentPrivate->dbg, "inputPortFlag = %d\n",inputPortFlag);
802b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRCOMM2(pComponentPrivate->dbg, "outputPortFlag = %d\n",outputPortFlag);
803fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (!(inputPortFlag && outputPortFlag))
804fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
805fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
806fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->InLoaded_readytoidle = 1;
807fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifndef UNDER_CE
808fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
809fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pthread_cond_wait(&pComponentPrivate->InLoaded_threshold, &pComponentPrivate->InLoaded_mutex);
810fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
811fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
812fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#else
813fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            OMX_WaitForEvent(&(pComponentPrivate->InLoaded_event));
814fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
815fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
816fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
817fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        cb.LCML_Callback = (void *) AACENCLCML_Callback;
818fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pLcmlHandle = (OMX_HANDLETYPE) AACENCGetLCMLHandle(pComponentPrivate);
819fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
820fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (pLcmlHandle == NULL)
821fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
822b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d :: AACENC: LCML Handle is NULL........exiting..\n",__LINE__);
823b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                            eError = OMX_ErrorHardware;
824b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                            pComponentPrivate->cbInfo.EventHandler (pHandle,
825b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                pHandle->pApplicationPrivate,
826b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_EventError,
827b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                eError,
828b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_TI_ErrorSevere,
829b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                NULL);
830fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
831fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
832fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
833fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        /* Got handle of dsp via phandle filling information about DSP
834fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        specific things */
835fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pLcmlDsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
836fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        eError = AACENCFill_LCMLInitParams(pHandle, pLcmlDsp, arr);
837fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if(eError != OMX_ErrorNone)
838fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
839b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error returned from AACENCFill_LCMLInitParams()\n",__LINE__);
840b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                            pComponentPrivate->cbInfo.EventHandler (pHandle,
841b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                pHandle->pApplicationPrivate,
842b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_EventError,
843b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                eError,
844b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_TI_ErrorMajor,
845b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                NULL);
846fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
847fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
848fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->pLcmlHandle = (LCML_DSP_INTERFACE *)pLcmlHandle;
849fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        /*filling create phase params */
850fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        cb.LCML_Callback = (void *) AACENCLCML_Callback;
851b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENC: Calling LCML_InitMMCodec...\n",__LINE__);
852fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
853fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        eError = LCML_InitMMCodecEx(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle,
854fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       p,&pLcmlHandle,(void *)p,&cb, (OMX_STRING)pComponentPrivate->sDeviceString);
855b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENC: After Calling LCML_InitMMCodec...\n",__LINE__);
856fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
857fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if(eError != OMX_ErrorNone)
858fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
859b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error returned from LCML_Init()\n",__LINE__);
860300f5d1faaea6cefa5f5cd3cec785cb82fbe4551Priyesh Bisla                            /* send an event to client */
861300f5d1faaea6cefa5f5cd3cec785cb82fbe4551Priyesh Bisla                            /* client should unload the component if the codec is not able to load */
862300f5d1faaea6cefa5f5cd3cec785cb82fbe4551Priyesh Bisla                            eError = OMX_ErrorInvalidState;
863b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                            pComponentPrivate->cbInfo.EventHandler (pHandle,
864b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                pHandle->pApplicationPrivate,
865b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_EventError,
866b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                eError,
867b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_TI_ErrorSevere,
868b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                NULL);
869fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
870fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
871fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
872fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef HASHINGENABLE
873fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        /* Enable the Hashing Code */
874fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        eError = LCML_SetHashingState(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, OMX_TRUE);
875fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (eError != OMX_ErrorNone)
876fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
877b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "Error: Failed to set Mapping State\n");
878fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
879fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
880fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
881fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        /* need check the resource with RM */
882b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRINT2(pComponentPrivate->dbg, "%d :: AACENC: About to call RMProxy_SendCommand\n", __LINE__);
883fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef RESOURCE_MANAGER_ENABLED
884fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
885fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
886b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENC: Returned from RMProxy_SendCommand\n", __LINE__);
887b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENC: RMProxy_SendCommand returned %d\n", __LINE__,rm_error);
888fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if(rm_error == OMX_ErrorNone)
889fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
890fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            /* resource is available */
891fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->curState = OMX_StateIdle;
892fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
893fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
894fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySetup);
895fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
896fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_AAC_Encoder_COMPONENT, OMX_StateIdle, 3456, NULL);
897fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
898fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        else if(rm_error == OMX_ErrorInsufficientResources)
899fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
900fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            /* resource is not available, need set state to OMX_StateWaitForResources */
901b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Insufficient resources\n", __LINE__);
902fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->curState = OMX_StateWaitForResources;
903fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->cbInfo.EventHandler(pHandle,
904fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   pHandle->pApplicationPrivate,
905fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_EventCmdComplete,
906fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_CommandStateSet,
907fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   pComponentPrivate->curState,
908fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   NULL);
909b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR2(pComponentPrivate->dbg, "%d :: AACENC: OMX_ErrorInsufficientResources\n", __LINE__);
910fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
911fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->curState = OMX_StateIdle;
912eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
913eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                        /* Decrement reference count with signal enabled */
914eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                        if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
915eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                            return OMX_ErrorUndefined;
916eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                        }
917eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
918fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->cbInfo.EventHandler(pHandle,
919fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               pHandle->pApplicationPrivate,
920fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               OMX_EventCmdComplete,
921fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               OMX_CommandStateSet,
922fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               pComponentPrivate->curState,
923fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               NULL);
924fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#else
925fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->curState = OMX_StateIdle;
926eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
927eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                /* Decrement reference count with signal enabled */
928eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
929eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                     return OMX_ErrorUndefined;
930eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                }
931eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
932fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->cbInfo.EventHandler( pHandle,
933fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        pHandle->pApplicationPrivate,
934fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        OMX_EventCmdComplete,
935fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        OMX_CommandStateSet,
936fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        pComponentPrivate->curState,
937fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        NULL);
938fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
939fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
940fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
941fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
942fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    else if (pComponentPrivate->curState == OMX_StateExecuting)
943fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
944fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
945fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
946fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState);
947fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
948fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
949b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENC: Setting Component to OMX_StateIdle\n",__LINE__);
950b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENC: About to Call MMCodecControlStop\n", __LINE__);
951fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
952b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        pComponentPrivate->bIsStopping = 1;
953b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin
954b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin						if (pComponentPrivate->codecStop_waitingsignal == 0){
955b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin							pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
956b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin						}
957fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
958fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                      MMCodecControlStop,(void *)pArgs);
959b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin
960b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin	                    if (pComponentPrivate->codecStop_waitingsignal == 0){
961b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin	                        pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
962b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin	                        pComponentPrivate->codecStop_waitingsignal = 0;
963b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin	                        pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
964b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin	                    }
965b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin
966fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if(eError != OMX_ErrorNone)
967fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
968b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec Stop..\n",__LINE__);
969b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                            pComponentPrivate->cbInfo.EventHandler (pHandle,
970b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                pHandle->pApplicationPrivate,
971b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_EventError,
972b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                eError,
973b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_TI_ErrorSevere,
974b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                NULL);
975fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
976fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
977b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENC: After MMCodecControlStop\n", __LINE__);
978fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->nNumOutputBufPending=0;
979fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
980fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef HASHINGENABLE
981fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        /*Hashing Change*/
982fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle;
983fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle);
984fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (eError != OMX_ErrorNone)
985fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
986b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "Error occurred in Codec mapping flush!\n");
987fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            break;
988fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
989fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
990fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
991fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
992fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
993fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
994fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    else if(pComponentPrivate->curState == OMX_StatePause)
995fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
996fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef HASHINGENABLE
997fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        /*Hashing Change*/
998fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle;
999fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle);
1000fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (eError != OMX_ErrorNone)
1001fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1002b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "Error occurred in Codec mapping flush!\n");
1003fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            break;
1004fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1005fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1006fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1007fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
1008fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState);
1009fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1010fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->curState = OMX_StateIdle;
1011fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1012fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef RESOURCE_MANAGER_ENABLED
1013fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1014fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_AAC_Encoder_COMPONENT, OMX_StateIdle, 3456, NULL);
1015fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1016eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
1017eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                        /* Decrement reference count with signal enabled */
1018eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                        if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
1019eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                            return OMX_ErrorUndefined;
1020eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                        }
1021eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
1022fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->cbInfo.EventHandler(pHandle,
1023fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               pHandle->pApplicationPrivate,
1024fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               OMX_EventCmdComplete,
1025fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               OMX_CommandStateSet,
1026fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               pComponentPrivate->curState,
1027fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               NULL);
1028fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
1029fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    else
1030fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
1031fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        /* This means, it is invalid state from application */
1032b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_ERROR4(pComponentPrivate->dbg, "%d :: AACENC: OMX_ErrorIncorrectStateTransition\n",__LINE__);
1033fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->cbInfo.EventHandler(pHandle,
1034fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               pHandle->pApplicationPrivate,
1035fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               OMX_EventError,
1036fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               OMX_ErrorIncorrectStateTransition,
1037fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               OMX_TI_ErrorMinor,
1038fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                               "Invalid State Error");
1039fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
1040fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    break;
1041fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1042fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1043fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                case OMX_StateExecuting:
1044b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                    OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENCHandleCommand: Cmd Executing \n",__LINE__);
1045fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    if(pComponentPrivate->curState == OMX_StateIdle)
1046fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
1047fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        /* Sending commands to DSP via LCML_ControlCodec third argument is not used for time being */
1048fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->bIsStopping = 0;
1049fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if(pComponentPrivate->dasfmode == 1)
1050fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1051b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_PRDSP2(pComponentPrivate->dbg, "%d :: ---- Comp: DASF Functionality is ON ---\n",__LINE__);
1052fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1053b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                            OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams,
1054b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                sizeof(AACENC_AudioCodecParams),
1055fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                AACENC_AudioCodecParams);
1056fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1057b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_PRDSP2(pComponentPrivate->dbg, "AACENC: pComponentPrivate->pParams %p \n",pComponentPrivate->pParams);
1058fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            if(pComponentPrivate->unNumChannels == 1)   /*MONO*/
1059fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                pComponentPrivate->pParams->iAudioFormat = 0x0001;
1060fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            else
1061fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                pComponentPrivate->pParams->iAudioFormat = 0x0002;
1062fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1063fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->pParams->iStrmId = pComponentPrivate->streamID;
1064fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->pParams->iSamplingRate = pComponentPrivate->ulSamplingRate;
1065fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1066fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pValues[0] = USN_STRMCMD_SETCODECPARAMS;
1067fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pValues[1] = (OMX_U32)pComponentPrivate->pParams;
1068fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pValues[2] = sizeof(AACENC_AudioCodecParams);
1069fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1070fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                         EMMCodecControlStrmCtrl,
1071fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                         (void *)pValues);
1072fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            if(eError != OMX_ErrorNone)
1073fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            {
1074b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                                OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Occurred in Codec StreamControl..\n",__LINE__);
1075b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                pComponentPrivate->cbInfo.EventHandler (pHandle,
1076b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                pHandle->pApplicationPrivate,
1077b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_EventError,
1078b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                eError,
1079b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_TI_ErrorSevere,
1080b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                NULL);
1081fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                goto EXIT;
1082fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            }
1083fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1084fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1085fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->ptAlgDynParams->audenc_dynamicparams.size                = sizeof(MPEG4AACENC_UALGParams);
1086fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->ptAlgDynParams->audenc_dynamicparams.bitRate             = pComponentPrivate->unBitrate;
1087fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->ptAlgDynParams->audenc_dynamicparams.sampleRate          = pComponentPrivate->ulSamplingRate;
1088fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->ptAlgDynParams->audenc_dynamicparams.numChannels         = (pComponentPrivate->unNumChannels==2)?1:0;   /* Reduced */
1089fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->ptAlgDynParams->useTns                                   = 1;
1090fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->ptAlgDynParams->usePns                                   = 1;
1091fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->ptAlgDynParams->outObjectType                            = pComponentPrivate->nObjectType;
1092fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->ptAlgDynParams->outFileFormat                            = pComponentPrivate->File_Format;
1093fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1094b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRDSP1(pComponentPrivate->dbg, "AACENC: dynamicparams.bitRate %d \n", (int)pComponentPrivate->unBitrate);
1095b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRDSP1(pComponentPrivate->dbg, "AACENC: dynamicparams.sampleRate %d \n ",pComponentPrivate->ulSamplingRate);
1096b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRDSP1(pComponentPrivate->dbg, "AACENC: dynamicparams.numChannels %d \n", pComponentPrivate->unNumChannels);
1097b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRDSP1(pComponentPrivate->dbg, "AACENC: ptAlgDynParams->outFileFormat %d \n",pComponentPrivate->File_Format);
1098fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1099fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pValues1[0] = IUALG_CMD_SETSTATUS;
1100fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pValues1[1] = (OMX_U32)pComponentPrivate->ptAlgDynParams;
1101fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pValues1[2] = sizeof(MPEG4AACENC_UALGParams);
1102fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1103fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1104fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                      EMMCodecControlAlgCtrl,(void *)pValues1);
1105fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if(eError != OMX_ErrorNone)
1106fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1107b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Occurred in Codec StreamControl..\n",__LINE__);
1108b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                            pComponentPrivate->cbInfo.EventHandler (pHandle,
1109b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                pHandle->pApplicationPrivate,
1110b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_EventError,
1111b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                eError,
1112b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_TI_ErrorSevere,
1113b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                NULL);
1114fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
1115fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1116b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENC: Algcontrol has been sent to DSP\n",__LINE__);
1117fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1118fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        eError = LCML_ControlCodec( ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1119fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       EMMCodecControlStart,(void *)pArgs);
1120fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if(eError != OMX_ErrorNone)
1121fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1122b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Occurred in Codec Start..\n", __LINE__);
1123b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                            pComponentPrivate->cbInfo.EventHandler (pHandle,
1124b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                pHandle->pApplicationPrivate,
1125b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_EventError,
1126b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                eError,
1127b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_TI_ErrorSevere,
1128b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                NULL);
1129fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
1130fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1131fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
1132fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                else if (pComponentPrivate->curState == OMX_StatePause)
1133fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                {
1134fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1135fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                  EMMCodecControlStart, (void *)pArgs);
1136fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    if (eError != OMX_ErrorNone)
1137fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
1138b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: While Resuming the codec\n",__LINE__);
1139b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                        pComponentPrivate->cbInfo.EventHandler (pHandle,
1140b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                pHandle->pApplicationPrivate,
1141b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_EventError,
1142b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                eError,
1143b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_TI_ErrorSevere,
1144b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                NULL);
1145fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        goto EXIT;
1146fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
1147fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    for (i=0; i < pComponentPrivate->nNumInputBufPending; i++)
1148fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
1149fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (pComponentPrivate->pInputBufHdrPending[i]!= NULL)
1150fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1151b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_PRINT2(pComponentPrivate->dbg, "i: %d \n",(int)i);
1152fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                AACENCGetCorresponding_LCMLHeader(pComponentPrivate, pComponentPrivate->pInputBufHdrPending[i]->pBuffer, OMX_DirInput, &pLcmlHdr);
1153fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                AACENC_SetPending(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i],OMX_DirInput,__LINE__);
1154fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1155fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                eError = LCML_QueueBuffer(
1156fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                            ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1157fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                            EMMCodecInputBuffer,
1158fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                            pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
1159fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                            pComponentPrivate->pInputBufHdrPending[i]->nAllocLen,
1160fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                            pComponentPrivate->pInputBufHdrPending[i]->nFilledLen,
1161fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                            (OMX_U8 *) pLcmlHdr->pIpParam,
1162fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                            sizeof(AACENC_UAlgInBufParamStruct),
1163fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                            NULL);
1164b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                               if(eError != OMX_ErrorNone){
1165b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                   OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: LCML QUEUE BUFFER\n",__LINE__);
1166b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                   pComponentPrivate->cbInfo.EventHandler (pHandle,
1167b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                pHandle->pApplicationPrivate,
1168b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_EventError,
1169b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                eError,
1170b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_TI_ErrorSevere,
1171b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                NULL);
1172b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                   goto EXIT;
1173b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                               }
1174fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1175fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
1176fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->nNumInputBufPending =0;
1177fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1178fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++)
1179fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
1180fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1181fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1182fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            if (pComponentPrivate->pOutputBufHdrPending[i]!= NULL)
1183fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            {
1184fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                AACENCGetCorresponding_LCMLHeader(pComponentPrivate, pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, OMX_DirOutput, &pLcmlHdr);
1185fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                AACENC_SetPending(pComponentPrivate,pComponentPrivate->pOutputBufHdrPending[i],OMX_DirOutput,__LINE__);
1186fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1187fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1188fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                eError = LCML_QueueBuffer(
1189b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                             ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1190b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                             EMMCodecOuputBuffer,
1191b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                             pComponentPrivate->pOutputBufHdrPending[i]->pBuffer,
1192b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                             pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen,
1193b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                             0,
1194b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                             (OMX_U8 *) pLcmlHdr->pOpParam,
1195b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                             sizeof(AACENC_UAlgOutBufParamStruct),
1196b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                             NULL);
1197b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                if(eError != OMX_ErrorNone){
1198b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                   OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: LCML QUEUE BUFFER\n",__LINE__);
1199b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                   pComponentPrivate->cbInfo.EventHandler (pHandle,
1200b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                pHandle->pApplicationPrivate,
1201b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_EventError,
1202b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                eError,
1203b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_TI_ErrorSevere,
1204b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                NULL);
1205b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                   goto EXIT;
1206b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                               }
1207fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            }
1208fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
1209fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->nNumOutputBufPending = 0;
1210fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1211fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1212fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
1213fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                else
1214fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                {
1215fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->cbInfo.EventHandler(pHandle,
1216fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                           pHandle->pApplicationPrivate,
1217fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                           OMX_EventError,
1218fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                           OMX_ErrorIncorrectStateTransition,
1219fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                           OMX_TI_ErrorMinor,
1220fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                           "Invalid State Error");
1221b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                    OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Invalid State Given by Application\n",__LINE__);
1222fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    goto EXIT;
1223fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
1224fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1225fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef RESOURCE_MANAGER_ENABLED
1226fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_AAC_Encoder_COMPONENT, OMX_StateExecuting, 3456, NULL);
1227fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1228fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1229fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1230eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                pComponentPrivate->curState = OMX_StateExecuting;
1231b65f253fdc60f6208a54911bee793d225f23cdf8James Dong
1232fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
1233fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySteadyState);
1234fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1235fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1236eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                /* Decrement reference count with signal enabled */
1237eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
1238eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                     return OMX_ErrorUndefined;
1239eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                }
1240fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1241fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                /*Send state change notificaiton to Application */
1242fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->cbInfo.EventHandler(pHandle,
1243fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pHandle->pApplicationPrivate,
1244fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_EventCmdComplete,
1245fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_CommandStateSet,
1246fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pComponentPrivate->curState,
1247fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       NULL);
1248fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                break;
1249fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1250fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1251fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                case OMX_StateLoaded:
1252b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: AACENC: AACENCHandleCommand: Cmd Loaded - curState = %d\n",__LINE__,pComponentPrivate->curState);
1253b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pInputBufferList->numBuffers = %d \n",__LINE__,pComponentPrivate->pInputBufferList->numBuffers);
1254b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pOutputBufferList->numBuffers = %d \n",__LINE__,pComponentPrivate->pOutputBufferList->numBuffers);
1255fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (pComponentPrivate->curState == OMX_StateWaitForResources)
1256fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1257b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENC: AACENCHandleCommand: Cmd Loaded\n",__LINE__);
1258fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1259fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
1260fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup);
1261fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1262fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->curState = OMX_StateLoaded;
1263fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1264fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
1265fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundaryCleanup);
1266fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1267fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1268eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                            /* Decrement reference count with signal enabled */
1269eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                            if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
1270eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                                return OMX_ErrorUndefined;
1271eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                            }
1272eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
1273fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->cbInfo.EventHandler(pHandle,
1274fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   pHandle->pApplicationPrivate,
1275fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_EventCmdComplete,
1276fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_CommandStateSet,
1277fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   pComponentPrivate->curState,
1278fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   NULL);
1279fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->bLoadedCommandPending = OMX_FALSE;
1280fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            break;
1281fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1282b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: AACENC: Inside OMX_StateLoaded State: \n",__LINE__);
1283fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (pComponentPrivate->curState != OMX_StateIdle &&
1284fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->curState != OMX_StateWaitForResources)
1285fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1286fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->cbInfo.EventHandler(pHandle,
1287fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   pHandle->pApplicationPrivate,
1288fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_EventError,
1289fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_ErrorIncorrectStateTransition,
1290fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_TI_ErrorMinor,
1291fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   "Incorrect State Transition");
1292b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Invalid State Given by Application\n",__LINE__);
1293fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
1294fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1295fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1296fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
1297fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup);
1298fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1299b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pComponentPrivate->pInputBufferList->numBuffers = %d \n",pComponentPrivate->pInputBufferList->numBuffers);
1300b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pComponentPrivate->pOutputBufferList->numBuffers = %d \n",pComponentPrivate->pOutputBufferList->numBuffers);
1301fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1302fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (pComponentPrivate->pInputBufferList->numBuffers ||
1303fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->pOutputBufferList->numBuffers)
1304fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1305fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->InIdle_goingtoloaded = 1;
1306fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1307fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifndef UNDER_CE
1308fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
1309fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pthread_cond_wait(&pComponentPrivate->InIdle_threshold, &pComponentPrivate->InIdle_mutex);
1310fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
1311fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1312fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#else
1313fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
1314fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1315fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1316fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1317fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        /* Now Deinitialize the component No error should be returned from this function. It should clean the system as much as possible */
1318b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENC: Before CodecControlDestroy \n",__LINE__);
1319fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1320fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                     EMMCodecControlDestroy, (void *)pArgs);
1321fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
1322fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        PERF_SendingCommand(pComponentPrivate->pPERF, -1, 0, PERF_ModuleComponent);
1323fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1324fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1325b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENC: After CodecControlDestroy \n",__LINE__);
1326fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (eError != OMX_ErrorNone)
1327fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1328b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: LCML_ControlCodec EMMCodecControlDestroy: no.  %x\n",__LINE__, eError);
1329fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
1330fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1331b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENCHandleCommand: Cmd Loaded\n",__LINE__);
1332fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifndef UNDER_CE
1333fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        /*Closing LCML Lib*/
1334fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        /* This flag is used in Deinit()  function to close LCML. */
1335fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->bCodecDestroyed = OMX_TRUE;
1336fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (pComponentPrivate->ptrLibLCML != NULL)
1337fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1338b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_PRDSP1(pComponentPrivate->dbg, "AAC: About to Close LCML %p \n",pComponentPrivate->ptrLibLCML);
1339b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_PRDSP1(pComponentPrivate->dbg, "AAC: Closed LCML \n");
1340fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            dlclose( pComponentPrivate->ptrLibLCML  );
1341fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->ptrLibLCML = NULL;
1342b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_PRDSP1(pComponentPrivate->dbg, "AAC: Closed LCML \n");
1343fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1344fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1345fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1346b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENC: After CodecControlDestroy \n",__LINE__);
1347fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (eError != OMX_ErrorNone)
1348fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1349b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: LCML_ControlCodec EMMCodecControlDestroy: no.  %x\n",__LINE__, eError);
1350fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
1351fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1352b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENCHandleCommand: Cmd Loaded\n",__LINE__);
1353fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        eError = EXIT_COMPONENT_THRD;
1354fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        /* Send StateChangeNotification to application */
1355fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        break;
1356fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1357fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1358fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                case OMX_StatePause:
1359fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (pComponentPrivate->curState != OMX_StateExecuting &&
1360fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->curState != OMX_StateIdle)
1361fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1362fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->cbInfo.EventHandler(pHandle,
1363fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   pHandle->pApplicationPrivate,
1364fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_EventError,
1365fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_ErrorIncorrectStateTransition,
1366fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_TI_ErrorMinor,
1367fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   "Incorrect State Transition");
1368b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Invalid State Given by Application\n",__LINE__);
1369fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
1370fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1371b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENC: about to call LCML_ControlCodec for PAUSE \n",__LINE__);
1372fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, EMMCodecControlPause, (void *)pArgs);
1373fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (eError != OMX_ErrorNone)
1374fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1375b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: in Pausing the codec\n",__LINE__);
1376fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
1377fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1378fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
1379fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState);
1380fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1381fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        break;
1382fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1383fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1384fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                case OMX_StateWaitForResources:
1385fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (pComponentPrivate->curState == OMX_StateLoaded)
1386fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1387fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1388fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef RESOURCE_MANAGER_ENABLED
1389fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_AAC_Encoder_COMPONENT, OMX_StateWaitForResources, 3456, NULL);
1390fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1391fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1392fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->curState = OMX_StateWaitForResources;
1393fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->cbInfo.EventHandler(pHandle,
1394fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   pHandle->pApplicationPrivate,
1395fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_EventCmdComplete,
1396fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_CommandStateSet,
1397fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   pComponentPrivate->curState,
1398fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   NULL);
1399fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1400fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        else
1401fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1402fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->cbInfo.EventHandler(pHandle,
1403fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   pHandle->pApplicationPrivate,
1404fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_EventError,
1405fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_ErrorIncorrectStateTransition,
1406fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   OMX_TI_ErrorMinor,
1407fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                   "Incorrect State Transition");
1408fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1409fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        break;
1410fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1411fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1412fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                case OMX_StateInvalid:
1413b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                         OMX_PRSTATE2(pComponentPrivate->dbg, "%d: HandleCommand: Cmd OMX_StateInvalid:\n",__LINE__);
1414fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         if (pComponentPrivate->curState != OMX_StateWaitForResources &&
1415fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                             pComponentPrivate->curState != OMX_StateInvalid &&
1416fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                             pComponentPrivate->curState != OMX_StateLoaded)
1417fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         {
1418fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                             eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1419fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                         EMMCodecControlDestroy, (void *)pArgs);
1420fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         }
1421fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1422fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         pComponentPrivate->curState = OMX_StateInvalid;
1423fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         pComponentPrivate->cbInfo.EventHandler( pHandle,
1424fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                 pHandle->pApplicationPrivate,
1425fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                 OMX_EventError,
1426fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                 OMX_ErrorInvalidState,
1427fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                 OMX_TI_ErrorSevere,
1428fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                 NULL);
1429fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1430fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         AACENC_CleanupInitParams(pHandle);
1431fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         break;
1432fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1433fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                case OMX_StateMax:
1434b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENCHandleCommand: Cmd OMX_StateMax::\n",__LINE__);
1435fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         break;
1436fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            } /* End of Switch */
1437fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1438fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
1439fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1440fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1441fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (command == OMX_CommandMarkBuffer)
1442fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
1443b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP2(pComponentPrivate->dbg, "AACENC: command OMX_CommandMarkBuffer received %d\n",__LINE__);
1444fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if(!pComponentPrivate->pMarkBuf)
1445fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1446b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP1(pComponentPrivate->dbg, "AACENC: command OMX_CommandMarkBuffer received %d\n",__LINE__);
1447fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            /* TODO Need to handle multiple marks */
1448fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->pMarkBuf = (OMX_MARKTYPE *)(commandData);
1449fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1450fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
1451fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (command == OMX_CommandPortDisable)
1452fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
1453fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if (!pComponentPrivate->bDisableCommandPending)
1454fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1455fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if(commandData == 0x0 || commandData == -1)
1456fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1457fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                /* disable port */
1458fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled = OMX_FALSE;
1459fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1460fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if(commandData == 0x1 || commandData == -1)
1461fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1462fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                char *pArgs = "damedesuStr";
1463fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled = OMX_FALSE;
1464fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1465fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                if (pComponentPrivate->curState == OMX_StateExecuting)
1466fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                {
1467fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->bNoIdleOnStop = OMX_TRUE;
1468b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                    OMX_PRINT2(pComponentPrivate->dbg, "AACENC: About to stop socket node line %d\n",__LINE__);
1469b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin
1470b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        pComponentPrivate->bIsStopping = 1;
1471b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin					if (pComponentPrivate->codecStop_waitingsignal == 0){
1472b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin						pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
1473b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin					}
1474fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1475fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                  MMCodecControlStop,(void *)pArgs);
1476b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin
1477b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                    if (pComponentPrivate->codecStop_waitingsignal == 0){
1478b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
1479b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        pComponentPrivate->codecStop_waitingsignal = 0;
1480b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
1481b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                    }
1482fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
1483fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1484fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1485fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1486fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if(commandData == 0x0)
1487fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1488fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if(!pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated)
1489fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1490fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                /* return cmdcomplete event if input unpopulated */
1491fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->cbInfo.EventHandler( pHandle,
1492fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        pHandle->pApplicationPrivate,
1493fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        OMX_EventCmdComplete,
1494fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        OMX_CommandPortDisable,INPUT_PORT, NULL);
1495fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bDisableCommandPending = 0;
1496fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1497fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            else
1498fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1499fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bDisableCommandPending = 1;
1500fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bDisableCommandParam = commandData;
1501fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1502fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1503fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1504fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if(commandData == 0x1)
1505fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1506fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (!pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated)
1507fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1508fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                /* return cmdcomplete event if output unpopulated */
1509fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->cbInfo.EventHandler( pHandle,
1510fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        pHandle->pApplicationPrivate,
1511fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        OMX_EventCmdComplete,
1512fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        OMX_CommandPortDisable,OUTPUT_PORT, NULL);
1513fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bDisableCommandPending = 0;
1514fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1515fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            else
1516fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1517fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bDisableCommandPending = 1;
1518fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bDisableCommandParam = commandData;
1519fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1520fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1521fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1522fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if(commandData == -1)
1523fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1524fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (!pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated &&
1525fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                !pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated)
1526fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1527fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1528fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                /* return cmdcomplete event if input & output unpopulated */
1529fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->cbInfo.EventHandler( pHandle,
1530fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        pHandle->pApplicationPrivate,
1531fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        OMX_EventCmdComplete,
1532fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        OMX_CommandPortDisable,INPUT_PORT, NULL);
1533fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1534fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->cbInfo.EventHandler( pHandle,
1535fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        pHandle->pApplicationPrivate,
1536fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        OMX_EventCmdComplete,
1537fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        OMX_CommandPortDisable,OUTPUT_PORT, NULL);
1538fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bDisableCommandPending = 0;
1539fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1540fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            else
1541fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1542fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bDisableCommandPending = 1;
1543fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bDisableCommandParam = commandData;
1544fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1545fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1546fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
1547fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1548fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (command == OMX_CommandPortEnable)
1549fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
1550fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if (!pComponentPrivate->bEnableCommandPending)
1551fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1552fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if(commandData == 0x0 || commandData == -1)
1553fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1554fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                /* enable in port */
1555b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: setting input port to enabled\n");
1556fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled = OMX_TRUE;
1557b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRCOMM2(pComponentPrivate->dbg, "WAKE UP!! HandleCommand: In utils setting output port to enabled. \n");
1558fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                if(pComponentPrivate->AlloBuf_waitingsignal)
1559fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                {
1560fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     pComponentPrivate->AlloBuf_waitingsignal = 0;
1561fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
1562b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled = %d\n",pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled);
1563fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1564fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1565fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if(commandData == 0x1 || commandData == -1)
1566fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1567fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                /* enable out port */
1568fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                if(pComponentPrivate->AlloBuf_waitingsignal)
1569fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                {
1570fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     pComponentPrivate->AlloBuf_waitingsignal = 0;
1571fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifndef UNDER_CE
1572fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1573fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
1574fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1575fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#else
1576fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event));
1577fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1578fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
1579fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                if (pComponentPrivate->curState == OMX_StateExecuting)
1580fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                {
1581fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    char *pArgs = "damedesuStr";
1582fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
1583fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1584b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                    OMX_PRCOMM1(pComponentPrivate->dbg, "AACENC: About to start socket node line %d\n",__LINE__);
1585fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    eError = LCML_ControlCodec( ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1586fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                   EMMCodecControlStart,(void *)pArgs);
1587fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
1588b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRCOMM1(pComponentPrivate->dbg, "AACENC: setting output port to enabled\n");
1589fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled = OMX_TRUE;
1590b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRCOMM1(pComponentPrivate->dbg, "AACENC: pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled = %d\n",pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled);
1591fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1592fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1593fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1594fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if(commandData == 0x0)
1595fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1596fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (pComponentPrivate->curState == OMX_StateLoaded || pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated)
1597fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1598fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->cbInfo.EventHandler(pHandle,
1599fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pHandle->pApplicationPrivate,
1600fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_EventCmdComplete,
1601fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_CommandPortEnable,
1602fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       INPUT_PORT,
1603fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       NULL);
1604fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bEnableCommandPending = 0;
1605fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1606fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            else
1607fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1608fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bEnableCommandPending = 1;
1609fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->nEnableCommandParam = commandData;
1610fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1611fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1612fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1613fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        else if(commandData == 0x1)
1614fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1615fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (pComponentPrivate->curState == OMX_StateLoaded || pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated)
1616fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1617fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->cbInfo.EventHandler( pHandle,
1618fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        pHandle->pApplicationPrivate,
1619fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        OMX_EventCmdComplete,
1620fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        OMX_CommandPortEnable,
1621fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        OUTPUT_PORT,
1622fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                        NULL);
1623fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bEnableCommandPending = 0;
1624fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1625fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            else
1626fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1627fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bEnableCommandPending = 1;
1628fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->nEnableCommandParam = commandData;
1629fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1630fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1631fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1632fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        else if(commandData == -1)
1633fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1634fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (pComponentPrivate->curState == OMX_StateLoaded ||
1635fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                (pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated
1636fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                && pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated))
1637fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1638fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->cbInfo.EventHandler(pHandle,
1639fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pHandle->pApplicationPrivate,
1640fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_EventCmdComplete,
1641fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_CommandPortEnable,
1642fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       INPUT_PORT,
1643fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       NULL);
1644fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->cbInfo.EventHandler(pHandle,
1645fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pHandle->pApplicationPrivate,
1646fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_EventCmdComplete,
1647fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_CommandPortEnable,
1648fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OUTPUT_PORT,
1649fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       NULL);
1650fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bEnableCommandPending = 0;
1651fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                AACENCFill_LCMLInitParamsEx(pHandle);
1652b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRDSP1(pComponentPrivate->dbg, "\nAACENC: calling fillexparams \n");
1653fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1654fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            else
1655fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1656fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bEnableCommandPending = 1;
1657fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->nEnableCommandParam = commandData;
1658fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1659fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1660fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1661fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifndef UNDER_CE
1662fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1663fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
1664fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1665fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#else
1666fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event));
1667fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1668fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1669fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
1670fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1671fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1672fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (command == OMX_CommandFlush)
1673fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
1674fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1675fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#if 0
1676fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        /*-------------- MANUAL FLUSH ----------------------------*/
1677fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1678fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if(commandData == 0x0 || commandData == -1)
1679fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1680fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if(pComponentPrivate->nUnhandledEmptyThisBuffers ==0) {
1681fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1682b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: UTIL: Flushing input port \n",__LINE__);
1683fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 pComponentPrivate->nOutStandingEmptyDones = 0;
1684fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 for (i=0; i < MAX_NUM_OF_BUFS; i++)
1685fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 {
1686fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->pInputBufHdrPending[i] = NULL;
1687fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 }
1688fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 pComponentPrivate->nNumInputBufPending=0;
1689fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++)
1690fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 {
1691fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1692fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->cbInfo.EmptyBufferDone (
1693fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                   pComponentPrivate->pHandle,
1694fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                   pComponentPrivate->pHandle->pApplicationPrivate,
1695fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                   pComponentPrivate->pInputBufferList->pBufHdr[i]
1696fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                   );
1697fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 }
1698fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 pComponentPrivate->cbInfo.EventHandler(pHandle,
1699fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                          pHandle->pApplicationPrivate,
1700fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                          OMX_EventCmdComplete,
1701fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                          OMX_CommandFlush,INPUT_PORT, NULL);
1702fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
1703fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            else{
1704fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bFlushInputPortCommandPending = OMX_TRUE;
1705fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1706fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1707fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1708fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if(commandData == 0x1 || commandData == -1)
1709fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1710fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (pComponentPrivate->nUnhandledFillThisBuffers == 0)  {
1711b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: UTIL: Flushing output port \n",__LINE__);
1712fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 pComponentPrivate->nOutStandingFillDones = 0;
1713fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 for (i=0; i < MAX_NUM_OF_BUFS; i++)
1714fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 {
1715fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->pOutputBufHdrPending[i] = NULL;
1716fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 }
1717fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 pComponentPrivate->nNumOutputBufPending=0;
1718fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++)
1719fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 {
1720fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1721fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->cbInfo.FillBufferDone (
1722fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                   pComponentPrivate->pHandle,
1723fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                   pComponentPrivate->pHandle->pApplicationPrivate,
1724fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                   pComponentPrivate->pOutputBufferList->pBufHdr[i]
1725fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                   );
1726fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 }
1727fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 pComponentPrivate->cbInfo.EventHandler(
1728fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                 pHandle, pHandle->pApplicationPrivate,
1729fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                 OMX_EventCmdComplete, OMX_CommandFlush,OUTPUT_PORT, NULL);
1730fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1731fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            else{
1732fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->bFlushOutputPortCommandPending = OMX_TRUE;
1733fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1734fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1735fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#else
1736fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1737fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        OMX_U32 aParam[3] = {0};
1738fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if (pComponentPrivate->nNumInputBufPending)
1739fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1740fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1741b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENC: Inside OMX_CommandFlush Command \n",__LINE__);
1742fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if(commandData == 0x0 || commandData == -1)
1743fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1744fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                if (pComponentPrivate->nUnhandledEmptyThisBuffers == 0)  {
1745fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
1746fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->nOutStandingFillDones = 0;
1747fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    aParam[0] = USN_STRMCMD_FLUSH;
1748fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    aParam[1] = 0x0;
1749fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    aParam[2] = 0x0;
1750b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                    OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: AACENCHandleCommand::Flushing input port \n",__LINE__);
1751fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    eError=LCML_ControlCodec(( (LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl,(void*)aParam);
1752fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    if (eError != OMX_ErrorNone)
1753fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
1754fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         goto EXIT;
1755fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
1756fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1757fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                else {
1758fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->bFlushInputPortCommandPending = OMX_TRUE;
1759fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
1760fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1761fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1762fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        else
1763fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1764b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin             OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: UTIL: Flushing input port \n",__LINE__);
1765fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin             pComponentPrivate->nOutStandingEmptyDones = 0;
1766fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin             for (i=0; i < MAX_NUM_OF_BUFS; i++)
1767fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin             {
1768fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->pInputBufHdrPending[i] = NULL;
1769fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin             }
1770fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin             pComponentPrivate->nNumInputBufPending=0;
1771fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin             for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++)
1772fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin             {
1773fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1774fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->cbInfo.EmptyBufferDone (
1775fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               pComponentPrivate->pHandle,
1776fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               pComponentPrivate->pHandle->pApplicationPrivate,
1777fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               pComponentPrivate->pInputBufferList->pBufHdr[i]
1778fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               );
17790db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong                AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->EmptybufferdoneCount);
17800db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong                SignalIfAllBuffersAreReturned(pComponentPrivate);
1781fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin             }
1782fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin             pComponentPrivate->cbInfo.EventHandler(pHandle,
1783fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                    pHandle->pApplicationPrivate,
1784fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                    OMX_EventCmdComplete,
1785fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                    OMX_CommandFlush,INPUT_PORT, NULL);
1786fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1787fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1788fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1789fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1790fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1791fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if (pComponentPrivate->nNumOutputBufPending)
1792fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1793fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if(commandData == 0x1 || commandData == -1)
1794fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1795fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                if (pComponentPrivate->nUnhandledFillThisBuffers == 0)  {
1796fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
1797fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->nOutStandingEmptyDones=0;
1798b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                    OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: AACENCHandleCommand::Flushing ouput queue \n",__LINE__);
1799fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    aParam[0] = USN_STRMCMD_FLUSH;
1800fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    aParam[1] = 0x1;
1801fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    aParam[2] = 0x0;
1802fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1803b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                    OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: AACENCHandleCommand::Flushing ouput port  \n",__LINE__);
1804fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam);
1805fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    if (eError != OMX_ErrorNone)
1806fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
1807fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        goto EXIT;
1808fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
1809fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1810fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                else {
1811fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->bFlushOutputPortCommandPending = OMX_TRUE;
1812fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
1813fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1814fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1815fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        else
1816fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1817b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: UTIL: Flushing output port \n",__LINE__);
1818fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->nOutStandingFillDones = 0;
1819fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            for (i=0; i < MAX_NUM_OF_BUFS; i++)
1820fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1821fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->pOutputBufHdrPending[i] = NULL;
1822fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1823fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->nNumOutputBufPending=0;
1824fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++)
1825fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1826fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1827fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 pComponentPrivate->cbInfo.FillBufferDone (
1828fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                  pComponentPrivate->pHandle,
1829fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                  pComponentPrivate->pHandle->pApplicationPrivate,
1830fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                  pComponentPrivate->pOutputBufferList->pBufHdr[i]
1831fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                  );
18320db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong                 AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->FillbufferdoneCount);
18330db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong                 SignalIfAllBuffersAreReturned(pComponentPrivate);
1834fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1835fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->cbInfo.EventHandler( pHandle,
1836fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                    pHandle->pApplicationPrivate,
1837fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                    OMX_EventCmdComplete,
1838fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                    OMX_CommandFlush,OUTPUT_PORT, NULL);
1839fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1840fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1841fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1842fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
1843fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1844fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinEXIT:
1845b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting AACENCHandleCommand Function\n",__LINE__);
1846b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Returning %d\n",__LINE__,eError);
1847b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    /* report the error to the client via event */
1848b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    if(eError != OMX_ErrorNone && eError != EXIT_COMPONENT_THRD){
1849b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: LCML QUEUE BUFFER\n",__LINE__);
1850b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        pComponentPrivate->cbInfo.EventHandler (pHandle,
1851b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                pHandle->pApplicationPrivate,
1852b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_EventError,
1853b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                eError,
1854b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_TI_ErrorSevere,
1855b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                NULL);
1856b65f253fdc60f6208a54911bee793d225f23cdf8James Dong
1857b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    }
1858fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return eError;
1859fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
1860fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1861fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1862fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
1863fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
1864fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* AACENCHandleDataBuf_FromApp() This function is called by the component when ever it
1865fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* receives the buffer from the application
1866fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
1867fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pComponentPrivate  Component private data
1868fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pBufHeader Buffer from the application
1869fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
1870fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @pre
1871fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
1872fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @post
1873fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
1874fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @return none
1875fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*/
1876fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
1877fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_ERRORTYPE AACENCHandleDataBuf_FromApp(OMX_BUFFERHEADERTYPE* pBufHeader, AACENC_COMPONENT_PRIVATE *pComponentPrivate)
1878fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
1879fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
1880fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_DIRTYPE eDir = 0;
1881fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_AACENC_BUFHEADERTYPE *pLcmlHdr = NULL;
1882fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
1883fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
1884fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1885b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Entering AACENCHandleDataBuf_FromApp - curState = %d\n",__LINE__,pComponentPrivate->curState);
1886fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1887fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /*Find the direction of the received buffer from buffer list*/
1888fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    eError = AACENCGetBufferDirection(pBufHeader, &eDir);
1889fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (eError != OMX_ErrorNone)
1890fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
1891b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: The pBufHeader is not found in the list\n",__LINE__);
1892fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
1893fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
1894fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1895fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (eDir == OMX_DirInput)
1896fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
1897fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate->nUnhandledEmptyThisBuffers--;
1898b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL:  Buffer Dir = input\n",__LINE__);
1899fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pPortDefIn = pComponentPrivate->pPortDef[OMX_DirInput];
1900fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if ((pBufHeader->nFilledLen > 0) || (pBufHeader->nFlags & OMX_BUFFERFLAG_EOS))
1901fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1902fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->bBypassDSP = 0;          /* flag for buffers with data */
1903fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            eError = AACENCGetCorresponding_LCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirInput, &pLcmlHdr);
1904fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (eError != OMX_ErrorNone)
1905fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1906b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: Error: Invalid INPUT Buffer Came ...\n",__LINE__);
1907fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                goto EXIT;
1908fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1909fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pLcmlHdr->pIpParam->bLastBuffer = 0;        /* it is not the last buffer yet  */
1910fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1911fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
1912fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            /*For Steady State Instumentation*/
1913fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    #if 0
1914fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if ((pComponentPrivate->nLcml_nCntIp == 1)) {
1915fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    PERF_Boundary(pComponentPrivate->pPERFcomp,
1916fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                  PERF_BoundaryStart | PERF_BoundarySteadyState);
1917fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1918fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    #endif
1919fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            PERF_SendingFrame(pComponentPrivate->pPERFcomp,
1920fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                              PREF(pBufHeader,pBuffer),
1921fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                              pPortDefIn->nBufferSize,
1922fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                              PERF_ModuleCommonLayer);
1923fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1924fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1925fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if(pBufHeader->nFlags & OMX_BUFFERFLAG_EOS)
1926fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1927b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: UTIL: End of Stream has been reached \n",__LINE__);
1928fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pLcmlHdr->pIpParam->bLastBuffer   = 1;  /* EOS flag for SN. - It is the last buffer with data for SN */
1929b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: pLcmlHdr->pIpParam->bLastBuffer = %d \n",__LINE__,(int)pLcmlHdr->pIpParam->bLastBuffer);
1930fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1931fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1932fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            /* Store time stamp information */
1933fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->timestampBufIndex[pComponentPrivate->IpBufindex] = pBufHeader->nTimeStamp;
1934fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->tickcountBufIndex[pComponentPrivate->IpBufindex] = pBufHeader->nTickCount;
1935fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->IpBufindex++;
1936fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->IpBufindex %= pComponentPrivate->pPortDef[OMX_DirOutput]->nBufferCountActual;
1937fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1938b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Sending input buffer header to Codec = %p to LCML\n",__LINE__,pBufHeader);
1939b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Sending INPUT BUFFER to Codec = %p\n",__LINE__,pBufHeader->pBuffer);
1940b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState);
1941b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] pComponentPrivate->bDspStoppedWhileExecuting = %ld\n",__LINE__,pComponentPrivate->bDspStoppedWhileExecuting);
1942fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1943fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (pComponentPrivate->curState == OMX_StateExecuting)
1944fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1945b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] The current state while sending the buffer = %d \n",__LINE__,pComponentPrivate->curState);
1946fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                if(!pComponentPrivate->bDspStoppedWhileExecuting)
1947fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                {
1948fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    if (!AACENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirInput))
1949fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
1950fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        AACENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirInput,__LINE__);
1951fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        eError = LCML_QueueBuffer(  pLcmlHandle->pCodecinterfacehandle,
1952fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                    EMMCodecInputBuffer,
1953fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                   (OMX_U8 *)pBufHeader->pBuffer,
1954fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                    pBufHeader->nAllocLen,
1955fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                    pBufHeader->nFilledLen,
1956fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                    (OMX_U8 *)pLcmlHdr->pIpParam,
1957fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                    sizeof(AACENC_UAlgInBufParamStruct),
1958fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                    NULL);
1959fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (eError != OMX_ErrorNone)
1960fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
1961b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: SetBuff: IP: Error Occurred\n",__LINE__);
1962fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            eError = OMX_ErrorHardware;
1963fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
1964fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
1965fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->lcml_nIpBuf++;
1966b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL:  [HandleData_FromApp] lcml_nIpBuf count :  %d\n",__LINE__, (int)pComponentPrivate->lcml_nIpBuf);
1967fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
1968fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
1969fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                else
1970fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                {
1971fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
1972fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    PERF_SendingFrame(pComponentPrivate->pPERFcomp,
1973fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                      PREF(pBufHeader, pBuffer),
1974fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                      0,
1975fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                      PERF_ModuleHLMM);
1976fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
1977fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->cbInfo.EmptyBufferDone (
1978fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                               pComponentPrivate->pHandle,
1979fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                               pComponentPrivate->pHandle->pApplicationPrivate,
1980fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                               pBufHeader
1981fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                               );
1982fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->nOutStandingEmptyDones--;
19830db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong                    AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->EmptybufferdoneCount);
19840db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong                    SignalIfAllBuffersAreReturned(pComponentPrivate);
1985fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
1986fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1987fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            else
1988fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
1989fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                /* Save received buffers */
1990fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader;
1991fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
1992fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
1993fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
1994fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        else
1995fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
1996fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->bBypassDSP = 1;          /* flag :   empty buffer */
1997b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] setting pComponentPrivate->bBypassDSP = 1 \n", __LINE__);
1998b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] Calling FillBufferDone\n", __LINE__);
1999fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2000fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
2001fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            PERF_SendingFrame(pComponentPrivate->pPERFcomp,
2002fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            PREF(pComponentPrivate->pOutputBufferList->pBufHdr[0],pBuffer),
2003fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            PREF(pComponentPrivate->pOutputBufferList->pBufHdr[0],nFilledLen),
2004fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            PERF_ModuleHLMM);
2005fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2006fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2007b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] (filled <0 or EOS )Calling FillBufferDone \n",__LINE__);
2008fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->cbInfo.FillBufferDone(pComponentPrivate->pHandle,
2009fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                       pComponentPrivate->pHandle->pApplicationPrivate,
2010fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                       pComponentPrivate->pOutputBufferList->pBufHdr[0]
2011fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                       );
2012fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->nOutStandingFillDones--;
20130db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->FillbufferdoneCount);
20140db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            SignalIfAllBuffersAreReturned(pComponentPrivate);
2015b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->FillbufferdoneCount = %ld \n",__LINE__,pComponentPrivate->FillbufferdoneCount);
2016b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->FillthisbufferCount = %ld \n",__LINE__,pComponentPrivate->FillthisbufferCount);
2017fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2018fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2019fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
2020fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            PERF_SendingFrame(pComponentPrivate->pPERFcomp,
2021fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            PREF(pComponentPrivate->pInputBufferList->pBufHdr[0], pBuffer),
2022fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            0,
2023fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            PERF_ModuleHLMM);
2024fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2025fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2026b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT1(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] (filled <0 or EOS )Calling EmptyBufferDone \n",__LINE__);
2027fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->cbInfo.EmptyBufferDone ( pComponentPrivate->pHandle,
2028fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                       pComponentPrivate->pHandle->pApplicationPrivate,
2029fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                       pComponentPrivate->pInputBufferList->pBufHdr[0]
2030fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                       );
2031fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->nOutStandingEmptyDones--;
20320db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->EmptybufferdoneCount);
20330db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            SignalIfAllBuffersAreReturned(pComponentPrivate);
2034b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->EmptybufferdoneCount = %ld \n",__LINE__,pComponentPrivate->EmptybufferdoneCount);
2035b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->EmptythisbufferCount = %ld \n",__LINE__,pComponentPrivate->EmptythisbufferCount);
2036fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2037fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2038fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if(pBufHeader->nFlags & OMX_BUFFERFLAG_EOS)
2039fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2040b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT2(pComponentPrivate->dbg, "%d :: UTIL: Component Detected EOS\n",__LINE__);
2041fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if(pComponentPrivate->dasfmode == 0)
2042fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
2043fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags |= OMX_BUFFERFLAG_EOS;
2044b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags = %d \n",__LINE__,(int)pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags);
2045fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
2046fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pComponentPrivate->pHandle->pApplicationPrivate,
2047fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_EventBufferFlag,
2048fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pComponentPrivate->pOutputBufferList->pBufHdr[0]->nOutputPortIndex,
2049fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags, NULL);
2050fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2051fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2052fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pBufHeader->nFlags = 0;
2053fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2054fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2055b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState);
2056fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if(pBufHeader->pMarkData)
2057fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2058b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Detected pBufHeader->pMarkData\n",__LINE__);
2059fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            /* copy mark to output buffer header */
2060b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRSTATE2(pComponentPrivate->dbg, "UTIL: pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
2061fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->pOutputBufferList->pBufHdr[0]->pMarkData = pBufHeader->pMarkData;
2062b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRSTATE2(pComponentPrivate->dbg, "UTIL: pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
2063fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->pOutputBufferList->pBufHdr[0]->hMarkTargetComponent = pBufHeader->hMarkTargetComponent;
2064b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRSTATE2(pComponentPrivate->dbg, "UTIL: pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
2065fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            /* trigger event handler if we are supposed to */
2066fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if(pBufHeader->hMarkTargetComponent == pComponentPrivate->pHandle && pBufHeader->pMarkData)
2067fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
2068b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRSTATE1(pComponentPrivate->dbg, "UTIL: pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
2069fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
2070fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pComponentPrivate->pHandle->pApplicationPrivate,
2071fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_EventMark,
2072fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       0,
2073fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       0,
2074fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pBufHeader->pMarkData);
2075fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2076fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2077fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2078fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if (pComponentPrivate->bFlushInputPortCommandPending) {
2079fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            OMX_SendCommand(pComponentPrivate->pHandle,OMX_CommandFlush,0,NULL);
2080fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2081fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2082fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2083fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2084fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2085fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (eDir == OMX_DirOutput)
2086fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2087fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        /* Make sure that output buffer is issued to output stream only when
2088fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        * there is an outstanding input buffer already issued on input stream
2089fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        */
2090b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: Buffer Dir = output\n",__LINE__);
2091b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->bIsStopping = %ld\n",__LINE__, pComponentPrivate->bIsStopping);
2092b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->bBypassDSP  = %ld\n",__LINE__, pComponentPrivate->bBypassDSP);
2093b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState);
2094fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2095fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate->nUnhandledFillThisBuffers--;
2096fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2097fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef ANDROID
2098fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if (pComponentPrivate->bFirstOutputBuffer){
2099fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        // if this is the first output buffer, fill the config data, then return the buffer (skip DSP)
2100fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            AACENCWriteConfigHeader(pComponentPrivate, pBufHeader);
2101b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRINT2(pComponentPrivate->dbg, "%d :: UTIL: AACENCWriteConfigHeader = %p\n",__LINE__, pBufHeader->pBuffer);
2102fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->cbInfo.FillBufferDone (
2103fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                   pComponentPrivate->pHandle,
2104fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                   pComponentPrivate->pHandle->pApplicationPrivate,
2105fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                   pBufHeader
2106fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                   );
2107fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate->bFirstOutputBuffer = 0;
21080db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->FillbufferdoneCount);
21090db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            SignalIfAllBuffersAreReturned(pComponentPrivate);
2110fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            goto EXIT;
2111fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2112fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2113fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2114fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if (!(pComponentPrivate->bIsStopping))
2115fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2116fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (pComponentPrivate->bBypassDSP == 0)
2117fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
2118b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Sending Output buffer header to Codec= %p to LCML\n",__LINE__,pBufHeader);
2119b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: Sending OUTPUT BUFFER to Codec = %p\n",__LINE__,pBufHeader->pBuffer);
2120fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
2121fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                PERF_SendingFrame(pComponentPrivate->pPERFcomp,
2122fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                 PREF(pBufHeader,pBuffer),
2123fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                  0,
2124fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                  PERF_ModuleCommonLayer);
2125fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2126fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2127b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate = %p\n",__LINE__,pComponentPrivate);
2128b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: pBufHeader = %p\n",__LINE__,pBufHeader);
2129b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: pBufHeader->pBuffer = %p\n",__LINE__,pBufHeader->pBuffer);
2130fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                eError = AACENCGetCorresponding_LCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirOutput, &pLcmlHdr);
2131b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState);
2132fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2133fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                if (pComponentPrivate->bBypassDSP == 0)
2134fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                {
2135b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                    OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp]pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState);
2136b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                    OMX_PRINT2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp]pComponentPrivate->bDspStoppedWhileExecuting = %ld\n",__LINE__,pComponentPrivate->bDspStoppedWhileExecuting);
2137fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2138fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    if (pComponentPrivate->curState == OMX_StateExecuting)
2139fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
2140fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (!AACENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput))
2141fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
2142fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            AACENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput,__LINE__);
2143fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->LastOutputBufferHdrQueued = pBufHeader;
2144fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pLcmlHdr->pOpParam->unNumFramesEncoded=0; /* Resetting the value  for each time*/
2145fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
2146fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                      EMMCodecOuputBuffer,
2147fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                      (OMX_U8 *)pBufHeader->pBuffer,
2148fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                      pBufHeader->nAllocLen,
2149fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                      pBufHeader->nFilledLen,
2150fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                      (OMX_U8 *)pLcmlHdr->pOpParam,
2151fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                      sizeof(AACENC_UAlgOutBufParamStruct),
2152fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                      NULL);
2153b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Queuing Ouput buffer buffer \n",__LINE__);
2154fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            if (eError != OMX_ErrorNone )
2155fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            {
2156b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                                OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: Issuing DSP OP: Error Occurred\n",__LINE__);
2157fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                eError = OMX_ErrorHardware;
2158fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                goto EXIT;
2159fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            }
2160fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate->lcml_nOpBuf++;
2161b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: tlcml_nOpBuf count : %d\n",__LINE__, (int)pComponentPrivate->lcml_nOpBuf);
2162fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
2163fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                  }
2164fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                  else if (pComponentPrivate->curState == OMX_StatePause)
2165fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                  {
2166b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->nNumOutputBufPending++ = %d \n",__LINE__,(int)pComponentPrivate->nNumOutputBufPending++);
2167b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: pBufHeader = %p \n",__LINE__, pBufHeader);
2168fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
2169fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                  }
2170fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
2171fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2172fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            else
2173fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
2174b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRDSP2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] OMX_DirOutput - bBypassDSP = %d \n", __LINE__, (int)pComponentPrivate->bBypassDSP);
2175b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp]pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState);
2176b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRDSP2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp]pComponentPrivate->bDspStoppedWhileExecuting = %ld\n",__LINE__,pComponentPrivate->bDspStoppedWhileExecuting);
2177fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2178fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                if (pComponentPrivate->curState == OMX_StateExecuting)
2179fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                {
2180fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    if (!AACENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput))
2181fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
2182fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        AACENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput,__LINE__);
2183fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->LastOutputBufferHdrQueued = pBufHeader;
2184b65f253fdc60f6208a54911bee793d225f23cdf8James Dong			if (pLcmlHdr != NULL) {
2185b65f253fdc60f6208a54911bee793d225f23cdf8James Dong			    pLcmlHdr->pOpParam->unNumFramesEncoded = 0; /* Resetting the value  for each time*/
2186b65f253fdc60f6208a54911bee793d225f23cdf8James Dong			}
2187fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
2188fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                  EMMCodecOuputBuffer,
2189fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                  (OMX_U8 *)pBufHeader->pBuffer,
2190fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                  pBufHeader->nAllocLen,
2191fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                  pBufHeader->nFilledLen,
2192fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                  (OMX_U8 *)pLcmlHdr->pOpParam,
2193fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                  sizeof(AACENC_UAlgOutBufParamStruct),
2194fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                  NULL);
2195fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        if (eError != OMX_ErrorNone )
2196fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        {
2197b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                            OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: Issuing DSP OP: Error Occurred\n",__LINE__);
2198fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            eError = OMX_ErrorHardware;
2199fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            goto EXIT;
2200fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        }
2201fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        pComponentPrivate->lcml_nOpBuf++;
2202b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_PRDSP2(pComponentPrivate->dbg, "%d :: UTIL: lcml_nOpBuf count : %d\n",__LINE__, (int)pComponentPrivate->lcml_nOpBuf);
2203fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
2204fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
2205fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                else
2206fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                {
2207fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
2208fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
2209fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2210fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2211fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2212fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if (pComponentPrivate->bFlushOutputPortCommandPending) {
2213fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            OMX_SendCommand( pComponentPrivate->pHandle,
2214fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                  OMX_CommandFlush,
2215fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                  1,NULL);
2216fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2217fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2218fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else
2219fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2220b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: BufferHeader  = %p, Buffer  = %p Unknown\n",__LINE__,pBufHeader, pBufHeader->pBuffer);
2221fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        eError = OMX_ErrorBadParameter;
2222fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2223fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinEXIT:
2224b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL:Exiting from  HandleDataBuf_FromApp ..........>>>>>\n",__LINE__);
2225b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    /* report the error to the client via event */
2226b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    if(eError != OMX_ErrorNone){
2227b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: LCML QUEUE BUFFER\n",__LINE__);
2228b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle,
2229b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                pComponentPrivate->pHandle->pApplicationPrivate,
2230b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_EventError,
2231b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                eError,
2232b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_TI_ErrorSevere,
2233b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                NULL);
2234b65f253fdc60f6208a54911bee793d225f23cdf8James Dong
2235b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    }
2236fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return eError;
2237fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
2238fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2239fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/*-------------------------------------------------------------------*/
2240fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
2241fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* AACENCGetBufferDirection () This function is used by the component thread to
2242fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* request a buffer from the application.  Since it was called from 2 places,
2243fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* it made sense to turn this into a small function.
2244fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
2245fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pData pointer to AAC Decoder Context Structure
2246fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pCur pointer to the buffer to be requested to be filled
2247fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
2248fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @retval none
2249fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin**/
2250fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/*-------------------------------------------------------------------*/
2251fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2252fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_ERRORTYPE AACENCGetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader, OMX_DIRTYPE *eDir)
2253fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
2254fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
2255fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    AACENC_COMPONENT_PRIVATE *pComponentPrivate = pBufHeader->pPlatformPrivate;
2256fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 nBuf=0;
2257fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_BUFFERHEADERTYPE *pBuf = NULL;
2258fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 i=0;
2259fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_S16 flag = 1;
2260fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2261b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Entering AACENCGetBufferDirection Function\n",__LINE__);
2262fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /*Search this buffer in input buffers list */
2263fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2264fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nBuf = pComponentPrivate->pInputBufferList->numBuffers;
2265fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    for(i=0; i<nBuf; i++)
2266fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2267fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pBuf = pComponentPrivate->pInputBufferList->pBufHdr[i];
2268fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if(pBufHeader == pBuf)
2269fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2270fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            *eDir = OMX_DirInput;
227115c9596da616836bbf2db19d2aa10f30bb6587a0James Dong            OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Buffer %p is INPUT BUFFER\n",__LINE__, pBufHeader);
2272fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            flag = 0;
2273fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            goto EXIT;
2274fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2275fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2276fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2277fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /*Search this buffer in input buffers list */
2278fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nBuf = pComponentPrivate->pOutputBufferList->numBuffers;
2279fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2280fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    for(i=0; i<nBuf; i++)
2281fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2282fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pBuf = pComponentPrivate->pOutputBufferList->pBufHdr[i];
2283fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if(pBufHeader == pBuf)
2284fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2285fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            *eDir = OMX_DirOutput;
228615c9596da616836bbf2db19d2aa10f30bb6587a0James Dong            OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Buffer %p is OUTPUT BUFFER\n",__LINE__, pBufHeader);
2287fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            flag = 0;
2288fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            goto EXIT;
2289fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2290fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2291fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2292fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (flag == 1)
2293fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2294b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: Buffer %p is Not Found in the List\n",__LINE__,pBufHeader);
2295fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        eError = OMX_ErrorUndefined;
2296fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
2297fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2298fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinEXIT:
2299b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Exiting AACENCGetBufferDirection Function\n",__LINE__);
2300fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return eError;
2301fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
2302fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2303fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* -------------------------------------------------------------------*/
2304fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
2305fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  *  AACENCLCML_Callback() function will be called LCML component to write the msg
2306fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  *
2307fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  * @param event                 Event which gives to details about USN status
2308fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  * @param void * args        //    args [0] //bufType;
2309fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                              //    args [1] //arm address fpr buffer
2310fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                              //    args [2] //BufferSize;
2311fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                              //    args [3]  //arm address for param
2312fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                              //    args [4] //ParamSize;
2313fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                              //    args [6] //LCML Handle
2314fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  * @retval OMX_NoError              Success, ready to roll
2315fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  *         OMX_Error_BadParameter   The input parameter pointer is null
2316fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin **/
2317fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/*-------------------------------------------------------------------*/
2318fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2319fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_ERRORTYPE AACENCLCML_Callback(TUsnCodecEvent event,void * args [10])
2320fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
2321fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin /*   OMX_S16 ret = 0; */
2322fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_COMPONENTTYPE *pHandle=NULL;
2323fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
2324fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U8 *pBuffer = args[1];
2325fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_AACENC_BUFHEADERTYPE *pLcmlHdr = NULL;;
2326fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_DSP_INTERFACE *pLcmlHandle = NULL;
2327fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    AACENC_COMPONENT_PRIVATE *pComponentPrivate_CC = NULL;
2328fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_S16 i = 0;
2329fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    int j =0, k=0 ;
2330fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2331fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef RESOURCE_MANAGER_ENABLED
2332fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE rm_error = OMX_ErrorNone;
2333fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2334fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2335fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate_CC = (AACENC_COMPONENT_PRIVATE*)((LCML_DSP_INTERFACE *)args[6])->pComponentPrivate;
2336b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate_CC->dbg, "%d:pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate_CC->curState);
2337fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2338fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinpHandle = pComponentPrivate_CC->pHandle;
2339fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2340fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    switch(event) {
2341fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2342fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        case EMMCodecDspError:
2343b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecDspError\n");
2344fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            break;
2345fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2346fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        case EMMCodecInternalError:
2347b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecInternalError\n");
2348fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            break;
2349fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2350fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        case EMMCodecInitError:
2351b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecInitError\n");
2352fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            break;
2353fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2354fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        case EMMCodecDspMessageRecieved:
2355b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecDspMessageRecieved\n");
2356fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            break;
2357fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2358fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        case EMMCodecBufferProcessed:
2359b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecBufferProcessed\n");
2360fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            break;
2361fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2362fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        case EMMCodecProcessingStarted:
2363b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingStarted\n");
2364fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            break;
2365fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2366fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        case EMMCodecProcessingPaused:
2367b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingPaused\n");
2368fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            break;
2369fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2370fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        case EMMCodecProcessingStoped:
2371b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingStoped\n");
2372fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            break;
2373fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2374fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        case EMMCodecProcessingEof:
2375b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingEof\n");
2376fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            break;
2377fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2378fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        case EMMCodecBufferNotProcessed:
2379b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecBufferNotProcessed\n");
2380fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            break;
2381fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2382fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        case EMMCodecAlgCtrlAck:
2383b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecAlgCtrlAck\n");
2384fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            break;
2385fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2386fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        case EMMCodecStrmCtrlAck:
2387b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecStrmCtrlAck\n");
2388fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            break;
2389fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2390fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        default:
2391b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  Got event = %d\n",event);
2392fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            break;
2393fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2394fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2395b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: UTIL: Entering the AACENCLCML_Callback Function\n",__LINE__);
2396b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT2(pComponentPrivate_CC->dbg, "UTIL: args = %p \n",args[0]);
2397b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate_CC->dbg, " %d :: UTIL: EMMCodecInputBuffer = %p \n",__LINE__,(void *)EMMCodecInputBuffer);
2398b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate_CC->dbg, " %d :: UTIL: EMMCodecOuputBuffer = %p \n",__LINE__,(void *)EMMCodecOuputBuffer);
2399b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT2(pComponentPrivate_CC->dbg, " %d :: UTIL:Entering the LCML_Callback() : event = %d\n",__LINE__,event);
2400b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: UTIL: pHandle:%p \n",__LINE__,pHandle);
2401b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: UTIL: pComponentPrivate_CC:%p \n",__LINE__,pComponentPrivate_CC);
2402b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: UTIL: pLcmlHdr:%p \n",__LINE__,pLcmlHdr);
2403b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin/*  OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: UTIL: pLcmlHdr->pIpParam:%p \n",__LINE__,pLcmlHdr->pIpParam); */
2404fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2405fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2406fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if(event == EMMCodecBufferProcessed)
2407fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2408b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: UTIL: GOT MESSAGE EMMCodecBufferProcessed \n",__LINE__);
2409fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if( (OMX_U32)args [0] == EMMCodecInputBuffer)
2410fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2411b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: UTIL: Input: pBuffer = %p\n",__LINE__, pBuffer);
2412fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            eError = AACENCGetCorresponding_LCMLHeader(pComponentPrivate_CC, pBuffer, OMX_DirInput, &pLcmlHdr);
2413fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2414fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
2415fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            PERF_ReceivedFrame(pComponentPrivate_CC->pPERFcomp,
2416fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               PREF(pLcmlHdr->buffer,pBuffer),
2417fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               0,
2418fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               PERF_ModuleCommonLayer);
2419fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2420fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2421fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            AACENC_ClearPending(pComponentPrivate_CC,pLcmlHdr->buffer,OMX_DirInput,__LINE__);
2422fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (eError != OMX_ErrorNone)
2423fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
2424b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: UTIL: Error: Invalid Buffer Came ...\n",__LINE__);
2425fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                goto EXIT;
2426fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2427b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRCOMM2(pComponentPrivate_CC->dbg, "Input CallBack %p\n", pLcmlHdr->buffer);
2428fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2429fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if (pComponentPrivate_CC->curState != OMX_StatePause)
2430fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2431fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2432fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
2433fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
2434fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                  PREF(pLcmlHdr->buffer,pBuffer),
2435fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                  0,
2436fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                  PERF_ModuleHLMM);
2437fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2438fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->cbInfo.EmptyBufferDone (pComponentPrivate_CC->pHandle,
2439fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pComponentPrivate_CC->pHandle->pApplicationPrivate,
2440fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pLcmlHdr->buffer);
24410db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate_CC->EmptybufferdoneCount);
24420db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            SignalIfAllBuffersAreReturned(pComponentPrivate_CC);
2443fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->nOutStandingEmptyDones--;
2444fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->lcml_nIpBuf--;
2445fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2446fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2447fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        else
2448fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2449b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_ERROR4(pComponentPrivate_CC->dbg, "UTIL: Couldn't calling EmptyBufferDone() because pComponentPrivate->curState = %d\n",pComponentPrivate_CC->curState);
2450fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->pInBufHdrPausedPending[pComponentPrivate_CC->PendingInPausedBufs++] = pLcmlHdr->buffer;
2451fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2452fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2453fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2454fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->nOutStandingEmptyDones++;
2455b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: pComponentPrivate->nOutStandingEmptyDones = %ld\n",__LINE__,pComponentPrivate_CC->nOutStandingEmptyDones);
2456fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2457fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        else if ((OMX_U32)args [0] == EMMCodecOuputBuffer)
2458fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2459b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER1(pComponentPrivate_CC->dbg, "%d :: UTIL: Output: pBuffer = %p\n",__LINE__, pBuffer);
2460fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->nOutStandingFillDones++;
2461b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: Incrementing nOutStandingFillDones = %d\n",__LINE__, (int)pComponentPrivate_CC->nOutStandingFillDones);
2462b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: pComponentPrivate_CC->nOutStandingFillDones = %ld\n",__LINE__, pComponentPrivate_CC->nOutStandingFillDones);
2463fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            eError = AACENCGetCorresponding_LCMLHeader(pComponentPrivate_CC, pBuffer, OMX_DirOutput, &pLcmlHdr);
2464fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            AACENC_ClearPending(pComponentPrivate_CC,pLcmlHdr->buffer,OMX_DirOutput,__LINE__);
2465fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (eError != OMX_ErrorNone)
2466fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
2467b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: UTIL: Error: Invalid Buffer Came ...\n",__LINE__);
2468fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                goto EXIT;
2469fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2470fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pLcmlHdr->buffer->nFilledLen = (OMX_U32)args[8];
2471b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: UTIL: pLcmlHdr->buffer->nFilledLen = %ld \n",__LINE__,pLcmlHdr->buffer->nFilledLen);
2472fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2473fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
2474fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            PERF_ReceivedFrame(pComponentPrivate_CC->pPERFcomp,
2475fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               PREF(pLcmlHdr->buffer,pBuffer),
2476fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               PREF(pLcmlHdr->buffer,nFilledLen),
2477fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               PERF_ModuleCommonLayer);
2478fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->nLcml_nCntOpReceived++;
2479fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if ((pComponentPrivate_CC->nLcml_nCntIp >= 1) && (pComponentPrivate_CC->nLcml_nCntOpReceived == 1))
2480fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
2481fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                PERF_Boundary(pComponentPrivate_CC->pPERFcomp,
2482fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                PERF_BoundaryStart | PERF_BoundarySteadyState);
2483fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2484fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2485fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->LastOutbuf = pLcmlHdr->buffer;    /* back up of processed buffer */
2486b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT2(pComponentPrivate_CC->dbg, "Output CallBack %p\n", pLcmlHdr->buffer);
2487b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT2(pComponentPrivate_CC->dbg, "size content  %d\n", (int)pLcmlHdr->buffer->nFilledLen);
2488fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2489fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* Previously in HandleDatabuffer form LCML */
2490fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2491fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        /* Copying time stamp information to output buffer */
2492fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pLcmlHdr->buffer->nTimeStamp = (OMX_TICKS)pComponentPrivate_CC->timestampBufIndex[pComponentPrivate_CC->OpBufindex];
2493fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pLcmlHdr->buffer->nTickCount = pComponentPrivate_CC->tickcountBufIndex[pComponentPrivate_CC->OpBufindex];
2494fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate_CC->OpBufindex++;
2495fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate_CC->OpBufindex %= pComponentPrivate_CC->pPortDef[OMX_DirOutput]->nBufferCountActual;
2496fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2497fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if (pComponentPrivate_CC->curState != OMX_StatePause)
2498fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2499fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2500b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: UTIL: Component Sending Filled Output buffer%p to App\n",__LINE__,pLcmlHdr->buffer);
2501b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "UTIL:: Calling FillBufferDone from Line %d\n",__LINE__);
2502fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2503fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
2504fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
2505fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                pLcmlHdr->buffer->pBuffer,
2506fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                pLcmlHdr->buffer->nFilledLen,
2507fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                PERF_ModuleHLMM);
2508fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2509fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2510fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef AACENC_DEBUG
2511fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            unsigned long TmpNumFrames = pLcmlHdr->pOpParam->unNumFramesEncoded;
2512b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: UTIL: Num frames: %lx \n",__LINE__,TmpNumFrames);
2513fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2514fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            for(k=0; k<MPEG4AACENC_MAX_OUTPUT_FRAMES; k++)
2515fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
2516b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRINT2(pComponentPrivate_CC->dbg, "%d Frame size[%d]: %lx \n",__LINE__,k,pLcmlHdr->pOpParam->unFrameSizes[k]);
2517fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2518fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pLcmlHdr->buffer->pOutputPortPrivate=pLcmlHdr->pOpParam;
2519fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->cbInfo.FillBufferDone (
2520fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               pHandle,
2521fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               pHandle->pApplicationPrivate,
2522fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               pLcmlHdr->buffer
2523fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                               );
25240db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate_CC->FillbufferdoneCount);
25250db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            SignalIfAllBuffersAreReturned(pComponentPrivate_CC);
2526fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->nOutStandingFillDones--;
2527fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->lcml_nOpBuf--;
2528fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2529fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        else
2530fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2531b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_ERROR4(pComponentPrivate_CC->dbg, "UTIL: Couldn't calling fillBufferDone() because pComponentPrivate->curState = %d\n",pComponentPrivate_CC->curState);
2532fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->pOutBufHdrPausedPending[pComponentPrivate_CC->PendingOutPausedBufs++] = pLcmlHdr->buffer;
2533fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2534fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2535fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2536fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2537fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2538fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2539fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2540fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (event == EMMCodecStrmCtrlAck)
2541fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2542b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin          OMX_PRDSP1(pComponentPrivate_CC->dbg, "%d :: UTIL: GOT MESSAGE USN_DSPACK_STRMCTRL \n",__LINE__);
2543fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin          if (args[1] == (void *)USN_STRMCMD_FLUSH)
2544fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin          {
2545fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 pHandle = pComponentPrivate_CC->pHandle;
2546fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 if ( args[2] == (void *)EMMCodecInputBuffer)
2547fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                 {
2548fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     if (args[0] == (void*)USN_ERR_NONE )
2549fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     {
2550b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                         OMX_PRCOMM1(pComponentPrivate_CC->dbg, "%d :: UTIL: Flushing input port \n",__LINE__);
2551fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         for (i=0; i < pComponentPrivate_CC->nNumInputBufPending; i++) {
2552fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
2553fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
2554fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                              PREF(pComponentPrivate_CC->pInputBufferList->pBufHdr[i],pBuffer),
2555fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                              0,PERF_ModuleHLMM);
2556fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2557fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate_CC->cbInfo.EmptyBufferDone (
2558fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                           pComponentPrivate_CC->pHandle,
2559fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                           pComponentPrivate_CC->pHandle->pApplicationPrivate,
2560fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                           pComponentPrivate_CC->pInputBufHdrPending[i]);
2561fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate_CC->pInputBufHdrPending[i] = NULL;
25620db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong                            AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate_CC->EmptybufferdoneCount);
25630db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong                            SignalIfAllBuffersAreReturned(pComponentPrivate_CC);
2564fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         }
2565fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         pComponentPrivate_CC->nNumInputBufPending=0;
2566fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
2567fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                  pHandle->pApplicationPrivate,
2568fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                  OMX_EventCmdComplete,
2569fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                                  OMX_CommandFlush,INPUT_PORT, NULL);
2570fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
2571fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    else
2572fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
2573b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                         OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: UTIL: LCML reported error while flushing input port\n",__LINE__);
2574fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         goto EXIT;
2575fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    }
2576fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                }
2577fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                else if ( args[2] == (void *)EMMCodecOuputBuffer)
2578fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                {
2579fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    if (args[0] == (void*)USN_ERR_NONE )
2580fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                    {
2581b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                         OMX_PRDSP1(pComponentPrivate_CC->dbg, "\tCallback FLUSH OUT %ld\n",pComponentPrivate_CC->nNumOutputBufPending);
2582fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         pComponentPrivate_CC->nOutStandingFillDones = 0;
2583fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         for (i=0; i < pComponentPrivate_CC->nNumOutputBufPending; i++)
2584fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         {
2585fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef __PERF_INSTRUMENTATION__
2586fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
2587fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            PREF(pComponentPrivate_CC->pOutputBufferList->pBufHdr[i],pBuffer),
2588fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            PREF(pComponentPrivate_CC->pOutputBufferList->pBufHdr[i],nFilledLen),
2589fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            PERF_ModuleHLMM);
2590fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2591fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate_CC->cbInfo.FillBufferDone (
2592fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                           pComponentPrivate_CC->pHandle,
2593fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                           pComponentPrivate_CC->pHandle->pApplicationPrivate,
2594fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                           pComponentPrivate_CC->pOutputBufHdrPending[i]
2595fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                           );
2596fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pComponentPrivate_CC->pOutputBufHdrPending[i] = NULL;
25970db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong                            AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate_CC->FillbufferdoneCount);
25980db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong                            SignalIfAllBuffersAreReturned(pComponentPrivate_CC);
2599fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         }
2600fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         pComponentPrivate_CC->nNumOutputBufPending=0;
2601fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                         pComponentPrivate_CC->cbInfo.EventHandler(
2602fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                         pHandle, pHandle->pApplicationPrivate,
2603fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                         OMX_EventCmdComplete, OMX_CommandFlush,OUTPUT_PORT, NULL);
2604fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     }
2605fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     else
2606fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     {
2607b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                        OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: UTIL: LCML reported error while flushing output port\n",__LINE__);
2608fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                        goto EXIT;
2609fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                     }
2610fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2611fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2612fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2613fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2614fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2615fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if(event == EMMCodecProcessingStoped)
2616fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
26170db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong        LOGI("AAC encoder received stop ack, waiting for all outstanding buffers to be returned");
26180db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong        pthread_mutex_lock(&bufferReturned_mutex);
26190db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong        while (pComponentPrivate_CC->EmptythisbufferCount != pComponentPrivate_CC->EmptybufferdoneCount ||
26200db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong               pComponentPrivate_CC->FillthisbufferCount  != pComponentPrivate_CC->FillbufferdoneCount) {
26210db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            pthread_cond_wait(&bufferReturned_condition, &bufferReturned_mutex);
26220db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong        }
26230db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong        pthread_mutex_unlock(&bufferReturned_mutex);
26240db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong        LOGI("AAC encoder has returned all buffers");
26250db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong
2626b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        pthread_mutex_lock(&pComponentPrivate_CC->codecStop_mutex);
2627b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        if(pComponentPrivate_CC->codecStop_waitingsignal == 0){
2628b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            pComponentPrivate_CC->codecStop_waitingsignal = 1;
2629b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            pthread_cond_signal(&pComponentPrivate_CC->codecStop_threshold);
2630b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            OMX_PRINT2(pComponentPrivate_CC->dbg, "stop ack. received. stop waiting for sending disable command completed\n");
2631b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        }
2632b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        pthread_mutex_unlock(&pComponentPrivate_CC->codecStop_mutex);
26330db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong
26340db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong        if (!pComponentPrivate_CC->bNoIdleOnStop)
2635fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2636fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->curState = OMX_StateIdle;
2637fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef RESOURCE_MANAGER_ENABLED
2638fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2639fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            rm_error = RMProxy_NewSendCommand(pComponentPrivate_CC->pHandle,
2640fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                           RMProxy_StateSet,
2641fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                           OMX_AAC_Encoder_COMPONENT,
2642fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                           OMX_StateIdle,
2643fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                           3456, NULL);
2644fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2645fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2646fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (pComponentPrivate_CC->bPreempted == 0) {
2647eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
2648eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                /* Decrement reference count with signal enabled */
2649eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                if(RemoveStateTransition(pComponentPrivate_CC, OMX_TRUE) != OMX_ErrorNone) {
2650eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                      return OMX_ErrorUndefined;
2651eced958917cca059f5e7222a83a44adc4e259c67Benny Wong                }
2652eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
2653fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate_CC->cbInfo.EventHandler(pComponentPrivate_CC->pHandle,
2654fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pComponentPrivate_CC->pHandle->pApplicationPrivate,
2655fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_EventCmdComplete,
2656fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_CommandStateSet,
2657fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pComponentPrivate_CC->curState,
2658fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       NULL);
2659fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2660fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            else {
2661fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate_CC->cbInfo.EventHandler(pComponentPrivate_CC->pHandle,
2662fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pComponentPrivate_CC->pHandle->pApplicationPrivate,
2663fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_EventError,
2664fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_ErrorResourcesPreempted,
2665fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_TI_ErrorMajor,
2666fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       NULL);
2667fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2668fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2669fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2670fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        else
2671fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2672b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: UTIL: setting bDspStoppedWhileExecuting\n",__LINE__);
2673fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->bDspStoppedWhileExecuting = OMX_TRUE;
2674b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: bNoIdleOnStop %ld \n", __LINE__,pComponentPrivate_CC->bNoIdleOnStop);
2675fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->bNoIdleOnStop= OMX_FALSE;
2676fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2677fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2678fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2679fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2680fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2681fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if(event == EMMCodecDspMessageRecieved)
2682fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2683b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: UTIL: GOT MESSAGE EMMCodecDspMessageRecieved \n",__LINE__);
2684b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRSTATE1(pComponentPrivate_CC->dbg, "%d :: UTIL: commandedState  = %p\n",__LINE__,args[0]);
2685b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: UTIL: arg1 = %p\n",__LINE__,args[1]);
2686b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: UTIL: arg2 = %p\n",__LINE__,args[2]);
2687fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if(0x0500 == (OMX_U32)args[2])
2688fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2689b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: UTIL: See Message Here\n",__LINE__);
2690fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2691fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2692fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2693fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2694fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if(event == EMMCodecAlgCtrlAck)
2695fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2696b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: UTIL: GOT MESSAGE USN_DSPACK_ALGCTRL \n",__LINE__);
2697fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2698fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2699fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2700fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (event == EMMCodecDspError)
2701fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2702b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_PRSTATE2(pComponentPrivate_CC->dbg, "%d :: commandedState  = %d\n",__LINE__,(int)args[0]);
2703b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: arg4 = %d\n",__LINE__,(int)args[4]);
2704b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: arg5 = %d\n",__LINE__,(int)args[5]);
2705b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d ::UTIL: EMMCodecDspError Here\n",__LINE__);
2706b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        switch ( (OMX_U32) args [4])
2707fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2708b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            /* USN_ERR_NONE,: Indicates that no error encountered during execution of the command and the command execution completed succesfully.
2709b65f253fdc60f6208a54911bee793d225f23cdf8James Dong             * USN_ERR_WARNING,: Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message.
2710b65f253fdc60f6208a54911bee793d225f23cdf8James Dong             * USN_ERR_PROCESS,: Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message.
2711b65f253fdc60f6208a54911bee793d225f23cdf8James Dong             * USN_ERR_PAUSE,: Indicates that execution of pause resulted in error.
2712b65f253fdc60f6208a54911bee793d225f23cdf8James Dong             * USN_ERR_STOP,: Indicates that execution of stop resulted in error.
2713b65f253fdc60f6208a54911bee793d225f23cdf8James Dong             * USN_ERR_ALGCTRL,: Indicates that execution of alg control resulted in error.
2714b65f253fdc60f6208a54911bee793d225f23cdf8James Dong             * USN_ERR_STRMCTRL,: Indiactes the execution of STRM control command, resulted in error.
2715b65f253fdc60f6208a54911bee793d225f23cdf8James Dong             * USN_ERR_UNKNOWN_MSG,: Indicates that USN received an unknown command. */
2716fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2717fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef _ERROR_PROPAGATION__
2718b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            case USN_ERR_PAUSE:
2719b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            case USN_ERR_STOP:
2720b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            case USN_ERR_ALGCTRL:
2721b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            case USN_ERR_STRMCTRL:
2722b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            case USN_ERR_UNKNOWN_MSG:
2723b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                {
2724b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                    pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
2725b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                    pComponentPrivate_CC->curState = OMX_StateInvalid;
2726b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                    pHandle = pComponentPrivate_CC->pHandle;
2727b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                    pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
2728b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                            pHandle->pApplicationPrivate,
2729b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                            OMX_EventError,
2730b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                            OMX_ErrorInvalidState,
2731b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                            OMX_TI_ErrorSevere,
2732b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                            NULL);
2733b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                }
2734b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                break;
2735eaaadaf5ebb5e352e2ed4a12714f5d2363da0dcdJames Dong#endif
2736eaaadaf5ebb5e352e2ed4a12714f5d2363da0dcdJames Dong
2737b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            case USN_ERR_WARNING:
2738b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            case USN_ERR_PROCESS:
2739b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                AACENC_HandleUSNError (pComponentPrivate_CC, (OMX_U32)args[5]);
2740b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                break;
2741b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            default:
2742b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                break;
2743eaaadaf5ebb5e352e2ed4a12714f5d2363da0dcdJames Dong        }
2744b65f253fdc60f6208a54911bee793d225f23cdf8James Dong
2745fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2746fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2747fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2748fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (event == EMMCodecProcessingPaused)
2749fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2750fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate_CC->bPauseCommandPending = OMX_TRUE;
2751fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        AACENC_TransitionToPause(pComponentPrivate_CC);
2752fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2753fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2754fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2755fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifdef _ERROR_PROPAGATION__
2756fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2757fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (event ==EMMCodecInitError)
2758fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2759fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        /* Cheking for MMU_fault */
2760fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if((args[4] == (void*)USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL))
2761fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2762b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: UTIL: MMU_Fault \n",__LINE__);
2763fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
2764b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRINT2(pComponentPrivate_CC->dbg, "State changed to OMX_StateInvalid Line %d\n",__LINE__);
2765fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2766fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->curState = OMX_StateInvalid;
2767fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pHandle = pComponentPrivate_CC->pHandle;
2768fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
2769fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pHandle->pApplicationPrivate,
2770fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_EventError,
2771fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_ErrorStreamCorrupt,
2772fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_TI_ErrorSevere,
2773fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       NULL);
2774fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2775fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2776fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2777fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2778fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (event ==EMMCodecInternalError)
2779fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2780fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        /* Cheking for MMU_fault */
2781fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if((args[4] == (void*)USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL))
2782fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2783b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: UTIL: MMU_Fault \n",__LINE__);
2784fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
2785b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRSTATE2(pComponentPrivate_CC->dbg, "State changed to OMX_StateInvalid Line %d\n",__LINE__);
2786fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2787fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->curState = OMX_StateInvalid;
2788fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pHandle = pComponentPrivate_CC->pHandle;
2789fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
2790fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       pHandle->pApplicationPrivate,
2791fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_EventError,
2792fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_ErrorStreamCorrupt,
2793fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       OMX_TI_ErrorSevere,
2794fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                       NULL);
2795fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2796fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2797fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2798fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2799fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinEXIT:
2800b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate_CC->dbg, "%d:pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate_CC->curState);
2801b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: UTIL: Exiting the LCML_Callback Function\n",__LINE__);
2802b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    /* report the error to the client via event */
2803b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    if(eError != OMX_ErrorNone){
2804b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_ERROR4(pComponentPrivate_CC->dbg, "%d:: Error: \n",__LINE__);
2805b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        pComponentPrivate_CC->cbInfo.EventHandler (pComponentPrivate_CC->pHandle,
2806b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                pComponentPrivate_CC->pHandle->pApplicationPrivate,
2807b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_EventError,
2808b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                eError,
2809b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                OMX_TI_ErrorSevere,
2810b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                NULL);
2811b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    }
2812fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return eError;
2813fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
2814fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2815fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* -------------------------------------------------------------------*/
2816fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
2817fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  *  AACENCGetCorresponding_LCMLHeader() function will be called by LCML_Callback
2818fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  *                                 component to write the msg
2819fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  * @param *pBuffer,          Event which gives to details about USN status
2820fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  * @param LCML_AACENC_BUFHEADERTYPE **ppLcmlHdr            //  args [0] //bufType;
2821fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2822fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  * @retval OMX_NoError              Success, ready to roll
2823fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  *         OMX_Error_BadParameter   The input parameter pointer is null
2824fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin **/
2825fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* -------------------------------------------------------------------*/
2826fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_ERRORTYPE AACENCGetCorresponding_LCMLHeader(AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U8 *pBuffer, OMX_DIRTYPE eDir, LCML_AACENC_BUFHEADERTYPE **ppLcmlHdr)
2827fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
2828fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2829fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
2830fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_AACENC_BUFHEADERTYPE *pLcmlBufHeader = NULL;
2831fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    int nIpBuf =0 ;
2832fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    int nOpBuf =0;
2833fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U16 i  =0;
2834fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2835fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    AACENC_COMPONENT_PRIVATE *pComponentPrivate_CC = NULL;
2836fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate_CC = pComponentPrivate;
2837fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2838fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nIpBuf=pComponentPrivate_CC->pInputBufferList->numBuffers;
2839fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nOpBuf=pComponentPrivate_CC->pOutputBufferList->numBuffers;
2840fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2841b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Entering AACENCGetCorresponding_LCMLHeader..\n",__LINE__);
2842fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2843fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if(eDir == OMX_DirInput) {
2844b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP1(pComponentPrivate->dbg, "%d :: UTIL: AACENCGetCorresponding_LCMLHeader -- eDir = %d \n",__LINE__,eDir);
2845fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pLcmlBufHeader = pComponentPrivate_CC->pLcmlBufHeader[INPUT_PORT];
2846b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP1(pComponentPrivate->dbg, "%d :: UTIL: Before corresponding LCML Header is Found \n",__LINE__);
2847fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        for(i=0; i<nIpBuf; i++) {
2848fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if(pBuffer == pLcmlBufHeader->buffer->pBuffer) {
2849fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                *ppLcmlHdr = pLcmlBufHeader;
2850b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRDSP2(pComponentPrivate->dbg, "%d::  UTIL: Corresponding LCML Header Found\n",__LINE__);
2851b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "::  UTIL: pBuffer = %p\n",pBuffer);
2852b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "::  UTIL: pLcmlBufHeader->buffer = %p\n",pLcmlBufHeader->buffer);
2853b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "::  UTIL: pLcmlBufHeader->buffer->pBuffer = %p\n",pLcmlBufHeader->buffer->pBuffer);
2854fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                goto EXIT;
2855fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2856fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pLcmlBufHeader++;
2857fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2858fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2859fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (eDir == OMX_DirOutput)
2860fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2861b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: AACENCGetCorresponding_LCMLHeader -- eDir = %d \n",__LINE__,eDir);
2862fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pLcmlBufHeader = pComponentPrivate_CC->pLcmlBufHeader[OUTPUT_PORT];
2863b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRINT2(pComponentPrivate->dbg, "%d :: UTIL: Before corresponding LCML Header is Found \n",__LINE__);
2864b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRBUFFER2(pComponentPrivate->dbg, "nOpBuf = %d\n",nOpBuf);
2865fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        for(i=0; i<nOpBuf; i++)
2866fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        {
2867b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
2868b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader = %p\n",pLcmlBufHeader);
2869b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader->buffer = %p\n",pLcmlBufHeader->buffer);
2870b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate->dbg, " pLcmlBufHeader->buffer->pBuffer = %p\n", pLcmlBufHeader->buffer->pBuffer);
2871b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
2872b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader = %p\n",pLcmlBufHeader);
2873b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader->buffer = %p\n",pLcmlBufHeader->buffer);
2874b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin            OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader->buffer->pBuffer = %p\n",pLcmlBufHeader->buffer->pBuffer);
2875fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if(pBuffer == pLcmlBufHeader->buffer->pBuffer)
2876fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            {
2877fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                *ppLcmlHdr = pLcmlBufHeader;
2878b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:: UTIL: Corresponding LCML Header Found\n",__LINE__);
2879b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, ":: UTIL: pBuffer = %p\n",pBuffer);
2880b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "::  UTIL: pLcmlBufHeader->buffer = %p\n",pLcmlBufHeader->buffer);
2881b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, ":: UTIL: pLcmlBufHeader->buffer->pBuffer = %p\n",pLcmlBufHeader->buffer->pBuffer);
2882fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                goto EXIT;
2883fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2884fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pLcmlBufHeader++;
2885fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2886fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2887fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else
2888fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
2889b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin      OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:: UTIL: Invalid Buffer Type :: exiting...\n",__LINE__);
2890fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2891fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2892fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinEXIT:
2893b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Exiting AACENCGetCorresponding_LCMLHeader..\n",__LINE__);
2894fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return eError;
2895fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
2896fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2897fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2898fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* -------------------------------------------------------------------*/
2899fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
2900fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  *  AACENC_GetLCMLHandle()
2901fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  *
2902fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  * @retval OMX_HANDLETYPE
2903fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin  *
2904fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin -------------------------------------------------------------------*/
2905fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_HANDLETYPE AACENCGetLCMLHandle(AACENC_COMPONENT_PRIVATE *pComponentPrivate)
2906fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
2907fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2908fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
2909fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_HANDLETYPE pHandle = NULL;
2910fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifndef UNDER_CE
2911fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    void *handle;
2912fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    char *error;
2913fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE (*fpGetHandle)(OMX_HANDLETYPE);
2914b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering AACENCGetLCMLHandle..\n",__LINE__);
2915fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    handle = dlopen("libLCML.so", RTLD_LAZY);
2916fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (!handle) {
2917fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        fputs(dlerror(), stderr);
2918fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
2919fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2920fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2921fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    fpGetHandle = dlsym (handle, "GetHandle");
2922fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if ((error = dlerror()) != NULL) {
2923fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        fputs(error, stderr);
2924fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
2925fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2926fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#else
2927fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    HINSTANCE hDLL;
2928fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE);
2929fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LPFNDLLFUNC1 fpGetHandle;
2930fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2931b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering AACENCGetLCMLHandle..\n",__LINE__);
2932fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2933fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    hDLL = LoadLibraryEx(TEXT("OAF_BML.dll"), NULL, 0);
2934fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (hDLL == NULL) {
2935b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "BML Load Failed!!!\n");
2936fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pHandle = NULL;
2937fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
2938fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2939fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2940fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    fpGetHandle = (LPFNDLLFUNC1)GetProcAddress(hDLL,TEXT("GetHandle"));
2941fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (!fpGetHandle) {
2942fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin      // handle the error
2943fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin      FreeLibrary(hDLL);
2944b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin      OMX_ERROR4(pComponentPrivate->dbg, "BML GetProcAddress Failed!!!\n");
2945fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin      pHandle = NULL;
2946fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin      goto EXIT;
2947fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2948fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#endif
2949fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    eError = (*fpGetHandle)(&pHandle);
2950fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if(eError != OMX_ErrorNone) {
2951fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        eError = OMX_ErrorUndefined;
2952b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "eError != OMX_ErrorNone...\n");
2953fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pHandle = NULL;
2954fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2955fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin#ifndef UNDER_CE
2956fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        dlclose(handle);                            /* got error - Close LCML lib  */
2957b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_ERROR4(pComponentPrivate->dbg, "AAC: [AACENCGetLCMLHandle] closing LCML \n");
2958fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        handle = NULL;
2959fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin #endif
2960fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        goto EXIT;
2961fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2962fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2963fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate= pComponentPrivate;
2964fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->ptrLibLCML=handle;           /* saving LCML lib pointer  */
2965b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRDSP2(pComponentPrivate->dbg, "AAC: ptrLibLCML = %p\n",pComponentPrivate->ptrLibLCML);
2966fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bGotLCML = OMX_TRUE;
2967fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2968fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinEXIT:
2969b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting AACENCGetLCMLHandle..\n",__LINE__);
2970fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return pHandle;
2971fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
2972fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2973fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ================================================================================= */
2974fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
2975fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @fn AACENC_SetPending() description for AACENC_SetPending
2976fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinAACENC_SetPending().
2977fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinThis component is called when a buffer is queued to the LCML
2978fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pComponent  handle for this instance of the component
2979fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
2980fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @pre
2981fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
2982fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @post
2983fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
2984fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @return OMX_ERRORTYPE
2985fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*/
2986fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ================================================================================ */
2987fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavinvoid AACENC_SetPending(AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber)
2988fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
2989fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U16 i;
2990fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
2991fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (eDir == OMX_DirInput) {
2992fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
2993fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
2994fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->pInputBufferList->bBufferPending[i] = 1;
2995b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "*******************INPUT BUFFER %d IS PENDING Line %ld******************************\n",i,lineNumber);
2996fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
2997fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
2998fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
2999fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else {
3000fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
3001fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
3002fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->pOutputBufferList->bBufferPending[i] = 1;
3003b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "*******************OUTPUT BUFFER %d IS PENDING Line %ld******************************\n",i,lineNumber);
3004fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
3005fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
3006fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3007fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
3008fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3009fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ================================================================================= */
3010fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
3011fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @fn AACENC_ClearPending() description for AACENC_ClearPending
3012fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinAACENC_ClearPending().
3013fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinThis component is called when a buffer is returned from the LCML
3014fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pComponent  handle for this instance of the component
3015fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
3016fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @pre
3017fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
3018fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @post
3019fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
3020fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @return OMX_ERRORTYPE
3021fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*/
3022fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ================================================================================ */
3023fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavinvoid AACENC_ClearPending(AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber)
3024fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
3025fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U16 i;
3026fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3027b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "pComponentPrivate = %p\n",pComponentPrivate);
3028b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER1(pComponentPrivate->dbg, "pBufHdr = %p\n",pBufHdr);
3029b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT2(pComponentPrivate->dbg, "eDir = %d\n",eDir);
3030fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3031fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (eDir == OMX_DirInput) {
3032fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
3033fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
3034fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->pInputBufferList->bBufferPending[i] = 0;
3035b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "*******************INPUT BUFFER %d IS RECLAIMED Line %ld******************************\n",i,lineNumber);
3036fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
3037fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
3038fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3039fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else {
3040fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
3041fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
3042fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                pComponentPrivate->pOutputBufferList->bBufferPending[i] = 0;
3043b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "*******************OUTPUT BUFFER %d IS RECLAIMED Line %ld******************************\n",i,lineNumber);
3044fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
3045fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
3046fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3047fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
3048fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3049fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ================================================================================= */
3050fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
3051fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @fn AACENC_IsPending() description for AACENC_IsPending
3052fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinAACENC_IsPending().
3053fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinThis method returns the pending status to the buffer
3054fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pComponent  handle for this instance of the component
3055fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
3056fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @pre
3057fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
3058fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @post
3059fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
3060fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @return OMX_ERRORTYPE
3061fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*/
3062fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ================================================================================ */
3063fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_U32 AACENC_IsPending(AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir)
3064fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
3065fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U16 i;
3066fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3067fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (eDir == OMX_DirInput) {
3068fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
3069fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
3070b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Buffer pending: pBufHdr = %p \n",__LINE__,pBufHdr);
3071fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                return pComponentPrivate->pInputBufferList->bBufferPending[i];
3072fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
3073fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
3074fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3075fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else {
3076fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
3077fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
3078b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin                OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Buffer pending: pBufHdr = %p \n",__LINE__,pBufHdr);
3079fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                return pComponentPrivate->pOutputBufferList->bBufferPending[i];
3080fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            }
3081fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
3082fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3083fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return -1;
3084fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
3085fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3086fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_ERRORTYPE AACENC_TransitionToPause(AACENC_COMPONENT_PRIVATE *pComponentPrivate)
3087fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
3088fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
3089fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3090b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "AACENC_TransitionToPause:::pComponentPrivate->nOutStandingFillDones = %ld\n",pComponentPrivate->nOutStandingFillDones );
3091b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "AACENC_TransitionToPause:::pComponentPrivate->nOutStandingEmptyDones = %ld\n",pComponentPrivate->nOutStandingEmptyDones );
3092fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (pComponentPrivate->nOutStandingFillDones <= 0 && pComponentPrivate->nOutStandingEmptyDones <= 0)
3093fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
3094fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate->curState = OMX_StatePause;
3095eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
3096eced958917cca059f5e7222a83a44adc4e259c67Benny Wong        /* Decrement reference count with signal enabled */
3097eced958917cca059f5e7222a83a44adc4e259c67Benny Wong        if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
3098eced958917cca059f5e7222a83a44adc4e259c67Benny Wong              return OMX_ErrorUndefined;
3099eced958917cca059f5e7222a83a44adc4e259c67Benny Wong        }
3100eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
3101fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
3102fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                pComponentPrivate->pHandle->pApplicationPrivate,
3103fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                OMX_EventCmdComplete,
3104fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                OMX_CommandStateSet,
3105fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                pComponentPrivate->curState,
3106fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                                                NULL);
3107fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bPauseCommandPending = OMX_FALSE;
3108fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3109fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return eError;
3110fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
3111fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3112fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3113fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
3114fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/**
3115fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* AACENCFill_LCMLInitParamsEx () This function is used by the component thread to
3116fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* fill the all of its initialization parameters, buffer deatils  etc
3117fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* to LCML structure,
3118fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
3119fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param pComponent  handle for this instance of the component
3120fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @param plcml_Init  pointer to LCML structure to be filled
3121fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
3122fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @pre
3123fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
3124fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @post
3125fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*
3126fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin* @return none
3127fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin*/
3128fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/* ========================================================================== */
3129fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_ERRORTYPE AACENCFill_LCMLInitParamsEx(OMX_HANDLETYPE pComponent)
3130fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
3131fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
3132fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 nIpBuf,nIpBufSize,nOpBuf,nOpBufSize;
3133fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U16 i;
3134fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_BUFFERHEADERTYPE *pTemp = NULL;
3135fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 size_lcml;
3136fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_AACENC_BUFHEADERTYPE *pTemp_lcml = NULL;
3137fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
3138fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    AACENC_COMPONENT_PRIVATE *pComponentPrivate = pHandle->pComponentPrivate;
3139fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3140b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENCFill_LCMLInitParams\n ",__LINE__);
3141fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
3142fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nIpBufSize = pComponentPrivate->pPortDef[INPUT_PORT]->nBufferSize;
3143fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
3144fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nOpBufSize = pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferSize;
3145fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3146b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: ------ Buffer Details -----------\n",__LINE__);
3147b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Input  Buffer Count = %ld \n",__LINE__,nIpBuf);
3148b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Input  Buffer Size = %ld\n",__LINE__,nIpBufSize);
3149b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Output Buffer Count = %ld\n",__LINE__,nOpBuf);
3150b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Output Buffer Size = %ld\n",__LINE__,nOpBufSize);
3151b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: ------ Buffer Details ------------\n",__LINE__);
3152fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3153fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    size_lcml = nIpBuf * sizeof(LCML_AACENC_BUFHEADERTYPE);
3154b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_AACENC_BUFHEADERTYPE);
3155b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRDSP2(pComponentPrivate->dbg, "pTemp_lcml %p to %p \n",pTemp_lcml,(pTemp_lcml + sizeof(pTemp_lcml) ));
3156fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3157fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->pLcmlBufHeader[INPUT_PORT] = pTemp_lcml;
3158fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    for (i=0; i<nIpBuf; i++) {
3159fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3160fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i];
3161fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
3162fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nAllocLen = nIpBufSize;
3163fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nFilledLen = nIpBufSize;
3164fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nVersion.s.nVersionMajor = AACENC_MAJOR_VER;
3165fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nVersion.s.nVersionMinor = AACENC_MINOR_VER;
3166fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
3167fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nTickCount = NOT_USED;
3168fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml->buffer = pTemp;
3169fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml->eDir = OMX_DirInput;
3170fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3171b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam, sizeof(AACENC_UAlgInBufParamStruct), AACENC_UAlgInBufParamStruct);
3172b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRDSP2(pComponentPrivate->dbg, "pTemp_lcml %p to %p \n",pTemp_lcml,(pTemp_lcml + sizeof(pTemp_lcml) ));
3173fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3174fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml->pIpParam->bLastBuffer = 0;
3175fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        /* This means, it is not a last buffer. This flag is to be modified by
3176fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin         * the application to indicate the last buffer */
3177fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nFlags = NORMAL_BUFFER;
3178fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml++;
3179fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3180fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3181fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    /* Allocate memory for all output buffer headers,  This memory pointer will be sent to LCML */
3182fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    size_lcml = nOpBuf * sizeof(LCML_AACENC_BUFHEADERTYPE);
3183fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3184b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_AACENC_BUFHEADERTYPE);
3185b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRDSP2(pComponentPrivate->dbg, "size_lcml %d to %lx \n", (int)size_lcml,(size_lcml + sizeof(size_lcml) ));
3186fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3187fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT] = pTemp_lcml;
3188fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3189fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3190fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3191b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "[AACENCFill_LCMLInitParamsEx] nOpBuf = %d\n", (int)nOpBuf);
3192b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "[AACENCFill_LCMLInitParamsEx] pComponentPrivate->pOutputBufferList->numBuffers = %d\n",pComponentPrivate->pOutputBufferList->numBuffers);
3193fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    for (i=0; i<nOpBuf; i++) {
3194b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin           OMX_PRDSP2(pComponentPrivate->dbg, "[AACENCFill_LCMLInitParamsEx] pTemp_lcml = %p\n",pTemp_lcml);
3195fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
3196fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
3197fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nAllocLen = nOpBufSize;
3198fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nFilledLen = nOpBufSize;
3199fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nVersion.s.nVersionMajor = AACENC_MAJOR_VER;
3200fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nVersion.s.nVersionMinor = AACENC_MINOR_VER;
3201fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pComponentPrivate->nVersion = pTemp->nVersion.nVersion;
3202fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
3203fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nTickCount = NOT_USED;
3204fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        /* This means, it is not a last buffer. This flag is to be modified by
3205fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin         * the application to indicate the last buffer */
3206fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml->buffer = pTemp;
3207fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml->eDir = OMX_DirOutput;
3208fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3209b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pOpParam, sizeof(AACENC_UAlgOutBufParamStruct), AACENC_UAlgOutBufParamStruct);
3210fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3211b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRINT2(pComponentPrivate->dbg, "\n pTemp_lcml->pOpParam %p \n",pTemp_lcml->pOpParam);
3212fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp->nFlags = NORMAL_BUFFER;
3213fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp++;
3214fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pTemp_lcml++;
3215fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3216fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bPortDefsAllocated = 1;
3217fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pComponentPrivate->bBypassDSP = 0;
3218fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3219fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinEXIT:
3220b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting Fill_LCMLInitParams\n",__LINE__);
3221b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
3222fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return eError;
3223fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
3224fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3225fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3226fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz ZavinOMX_ERRORTYPE AACENCWriteConfigHeader(AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr){
3227fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3228fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_ERRORTYPE eError = OMX_ErrorNone;
3229fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 nPosition = 0;
3230fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 nNumBitsWritten = 0;
3231fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 nBytePosition = 0;
3232fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U8  nBitPosition =  0;
3233fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U8  nBits = 0;
3234fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U32 tempData = 0;
3235fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U8 rateIndex = 0;
3236fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_U16 nBuf = 0;
3237fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin	OMX_U16 nBuf2 = 0;
3238fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    //nBytePosition = nPosition / 8;  //add this back if we need to handle more than 4 bytes (U32).
3239fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    //nBitPosition =  nPosition % 8;
3240fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    memset(pBufHdr->pBuffer, 0x0, pBufHdr->nAllocLen); // make sure we start with zeroes
3241fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3242fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nBits = 5; //audioObjectType
3243fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nPosition += nBits;
3244b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRINT2(pComponentPrivate->dbg, "profile is %d\n", pComponentPrivate->aacParams[OUTPUT_PORT]->eAACProfile);
3245fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (pComponentPrivate->aacParams[OUTPUT_PORT]->eAACProfile == OMX_AUDIO_AACObjectLC)
3246fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
3247fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        tempData = AACENC_OBJ_TYP_LC << (16-nPosition);
3248b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin        OMX_PRINT2(pComponentPrivate->dbg, "profile is LC, tempData = 2 << (32-5) = %ld\n", tempData);
3249fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3250fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (pComponentPrivate->aacParams[OUTPUT_PORT]->eAACProfile == OMX_AUDIO_AACObjectHE)
3251fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
3252fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        tempData = AACENC_OBJ_TYP_HEAAC << (16-nPosition);
3253fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3254fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (pComponentPrivate->aacParams[OUTPUT_PORT]->eAACProfile == OMX_AUDIO_AACObjectHE_PS)
3255fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    {
3256fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        tempData = AACENC_OBJ_TYP_PS << (16-nPosition);
3257fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3258fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nBuf = tempData;
3259fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3260fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nBits = 4; //SamplingFrequencyIndex
3261fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nPosition += nBits;
3262fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    rateIndex = AACEnc_GetSampleRateIndexL(pComponentPrivate->aacParams[OUTPUT_PORT]->nSampleRate);
3263fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    tempData = rateIndex << (16-nPosition);
3264fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nBuf |= tempData;
3265b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "CONFIG BUFFER = %d\n\n", nBuf);
3266fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3267fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nBits = 4; //channelConfiguration
3268fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nPosition += nBits;
3269fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    tempData = pComponentPrivate->aacParams[OUTPUT_PORT]->nChannels << (16-nPosition);
3270fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    nBuf |= tempData;
3271fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3272fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    //@TODO add the rest of the AudioSpecificConfigData
3273fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3274fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin	nBuf2 =	(nBuf>> 8) | (nBuf << 8); /* Changing Endianess */
3275fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3276b44cdb1b44b144d09e8ec950d1e8e4c280064056Rebecca Schultz Zavin    OMX_PRBUFFER2(pComponentPrivate->dbg, "CONFIG BUFFER = %d\n\n", nBuf2);
3277fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3278fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    memcpy(pBufHdr->pBuffer, &nBuf2, sizeof(OMX_U16));
3279fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pBufHdr->nFlags = NORMAL_BUFFER;  // clear any other flags then add the needed ones
3280fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pBufHdr->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
3281fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pBufHdr->nFlags |= OMX_BUFFERFLAG_CODECCONFIG;
3282fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pBufHdr->nFilledLen = sizeof(OMX_U16); //need make this dynamic for non basic LC cases.
3283fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3284fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return eError;
3285fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
3286fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3287fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/*=======================================================================*/
3288fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/*! @fn AACDec_GetSampleRateIndexL
3289fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3290fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * @brief Gets the sample rate index
3291fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3292fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * @param  aRate : Actual Sampling Freq
3293fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3294fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin * @Return  Index
3295fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3296fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin */
3297fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin/*=======================================================================*/
3298fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavinint AACEnc_GetSampleRateIndexL( const int aRate)
3299fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
3300fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    int index = 0;
3301fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3302fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    switch( aRate ){
3303fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    case 96000:
3304fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        index = 0;
3305fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        break;
3306fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    case 88200:
3307fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        index = 1;
3308fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        break;
3309fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    case 64000:
3310fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        index = 2;
3311fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        break;
3312fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    case 48000:
3313fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        index = 3;
3314fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        break;
3315fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    case 44100:
3316fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        index = 4;
3317fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        break;
3318fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    case 32000:
3319fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        index = 5;
3320fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        break;
3321fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    case 24000:
3322fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        index = 6;
3323fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        break;
3324fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    case 22050:
3325fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        index = 7;
3326fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        break;
3327fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    case 16000:
3328fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        index = 8;
3329fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        break;
3330fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    case 12000:
3331fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        index = 9;
3332fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        break;
3333fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    case 11025:
3334fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        index = 10;
3335fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        break;
3336fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    case 8000:
3337fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        index = 11;
3338fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        break;
3339fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    default:
3340fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        break;
3341fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3342fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3343fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    return index;
3344fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
3345fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3346b65f253fdc60f6208a54911bee793d225f23cdf8James Dong/*  =========================================================================*/
33470db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong/**  func    AACENC_HandleUSNError
33480db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong *
33490db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong *  desc    Handles error messages returned by the dsp
33500db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong *
33510db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong *@return n/a
33520db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong */
3353b65f253fdc60f6208a54911bee793d225f23cdf8James Dong/*  =========================================================================*/
3354b65f253fdc60f6208a54911bee793d225f23cdf8James Dongvoid AACENC_HandleUSNError (AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg)
3355b65f253fdc60f6208a54911bee793d225f23cdf8James Dong{
3356b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    OMX_COMPONENTTYPE *pHandle = NULL;
3357b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    OMX_U32 i;
3358b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    switch (arg)
3359b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    {
3360fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3361b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        case IUALG_WARN_CONCEALED:
3362b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        case IUALG_WARN_UNDERFLOW:
3363b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        case IUALG_WARN_OVERFLOW:
3364b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        case IUALG_WARN_ENDOFDATA:
3365b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm Error" );
3366b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            /* all of these are informative messages, Algo can recover, no need to notify the
3367b65f253fdc60f6208a54911bee793d225f23cdf8James Dong             * IL Client at this stage of the implementation */
3368b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            break;
3369b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        case IUALG_WARN_PLAYCOMPLETED:
3370fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3371b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            {
3372b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                OMX_PRINT2(pComponentPrivate->dbg, "%d :: UTIL: IUALG_WARN_PLAYCOMPLETED/USN_ERR_WARNING event received\n", __LINE__);
3373b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                pComponentPrivate->bPlayCompleteFlag = 1;
3374b65f253fdc60f6208a54911bee793d225f23cdf8James Dong#ifndef UNDER_CE
3375b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
3376b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                       pComponentPrivate->pHandle->pApplicationPrivate,
3377b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                       OMX_EventBufferFlag,
3378b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                       (OMX_U32)NULL,
3379b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                       OMX_BUFFERFLAG_EOS,
3380b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                       NULL);
3381b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                pComponentPrivate->pLcmlBufHeader[0]->pIpParam->bLastBuffer = 0;
3382b65f253fdc60f6208a54911bee793d225f23cdf8James Dong#else
3383b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                /* add callback to application to indicate SN/USN has completed playing of current set of date */
3384b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
3385b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                       pComponentPrivate->pHandle->pApplicationPrivate,
3386b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                       OMX_EventBufferFlag,
3387b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                       (OMX_U32)NULL,
3388b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                       OMX_BUFFERFLAG_EOS,
3389b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                                                       NULL);
3390b65f253fdc60f6208a54911bee793d225f23cdf8James Dong#endif
3391b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            }
3392b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            break;
339336733d62c0d4c565da10b34978e587d0fda0f1adJames Dong
3394b65f253fdc60f6208a54911bee793d225f23cdf8James Dong#ifdef _ERROR_PROPAGATION__
3395b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        case IUALG_ERR_BAD_HANDLE:
3396b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        case IUALG_ERR_DATA_CORRUPT:
3397b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        case IUALG_ERR_NOT_SUPPORTED:
3398b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        case IUALG_ERR_ARGUMENT:
3399b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        case IUALG_ERR_NOT_READY:
3400b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        case IUALG_ERR_GENERAL:
3401b65f253fdc60f6208a54911bee793d225f23cdf8James Dong
3402b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            {
3403b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                /* all of these are fatal messages, Algo can not recover
3404b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                 * hence return an error */
3405b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm Error, cannot recover" );
3406b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                pComponentPrivate->bIsInvalidState=OMX_TRUE;
3407b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                pComponentPrivate->curState = OMX_StateInvalid;
3408b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                pHandle = pComponentPrivate->pHandle;
3409b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                pComponentPrivate->cbInfo.EventHandler(pHandle,
3410b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                        pHandle->pApplicationPrivate,
3411b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                        OMX_EventError,
3412b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                        OMX_ErrorInvalidState,
3413b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                        OMX_TI_ErrorSevere,
3414b65f253fdc60f6208a54911bee793d225f23cdf8James Dong                        NULL);
3415b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            }
3416b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            break;
3417eaaadaf5ebb5e352e2ed4a12714f5d2363da0dcdJames Dong#endif
3418b65f253fdc60f6208a54911bee793d225f23cdf8James Dong        default:
3419b65f253fdc60f6208a54911bee793d225f23cdf8James Dong            break;
3420b65f253fdc60f6208a54911bee793d225f23cdf8James Dong    }
3421b65f253fdc60f6208a54911bee793d225f23cdf8James Dong}
3422fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3423fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3424b65f253fdc60f6208a54911bee793d225f23cdf8James Dong#ifdef RESOURCE_MANAGER_ENABLED
3425b65f253fdc60f6208a54911bee793d225f23cdf8James Dongvoid AACENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
3426fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin{
3427fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
3428fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_STATETYPE state = OMX_StateIdle;
3429fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
3430fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    AACENC_COMPONENT_PRIVATE *pCompPrivate = NULL;
3431fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3432fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    pCompPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
3433fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3434fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted) {
3435fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        if (pCompPrivate->curState == OMX_StateExecuting ||
3436fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pCompPrivate->curState == OMX_StatePause) {
3437fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
3438fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
3439fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3440fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin            pCompPrivate->bPreempted = 1;
3441fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        }
3442fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3443fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
3444fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin        pCompPrivate->cbInfo.EventHandler (
3445fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            pHandle, pHandle->pApplicationPrivate,
3446fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            OMX_EventResourcesAcquired, 0,0,
3447fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin                            NULL);
3448fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3449fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3450fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin    }
3451fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin
3452fb3766f18a2c18b6f4798a6a631fdb88fcacd1dcRebecca Schultz Zavin}
3453b65f253fdc60f6208a54911bee793d225f23cdf8James Dong#endif
3454eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
3455eced958917cca059f5e7222a83a44adc4e259c67Benny WongOMX_ERRORTYPE AddStateTransition(AACENC_COMPONENT_PRIVATE* pComponentPrivate) {
3456eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    OMX_ERRORTYPE eError = OMX_ErrorNone;
3457eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
3458eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    if(pthread_mutex_lock(&pComponentPrivate->mutexStateChangeRequest)) {
3459eced958917cca059f5e7222a83a44adc4e259c67Benny Wong       return OMX_ErrorUndefined;
3460eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    }
3461eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    /* Increment state change request reference count */
3462eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    pComponentPrivate->nPendingStateChangeRequests++;
3463eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
3464eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
3465eced958917cca059f5e7222a83a44adc4e259c67Benny Wong       return OMX_ErrorUndefined;
3466eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    }
3467eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    return eError;
3468eced958917cca059f5e7222a83a44adc4e259c67Benny Wong}
3469eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
3470eced958917cca059f5e7222a83a44adc4e259c67Benny WongOMX_ERRORTYPE RemoveStateTransition(AACENC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BOOL bEnableSignal) {
3471eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    OMX_ERRORTYPE eError = OMX_ErrorNone;
3472eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
3473eced958917cca059f5e7222a83a44adc4e259c67Benny Wong     /* Decrement state change request reference count*/
3474eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    if(pthread_mutex_lock(&pComponentPrivate->mutexStateChangeRequest)) {
3475eced958917cca059f5e7222a83a44adc4e259c67Benny Wong       return OMX_ErrorUndefined;
3476eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    }
3477eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    pComponentPrivate->nPendingStateChangeRequests--;
3478eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
3479eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    /* If there are no more pending requests, signal the thread waiting on this*/
3480eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    if(!pComponentPrivate->nPendingStateChangeRequests && bEnableSignal) {
3481eced958917cca059f5e7222a83a44adc4e259c67Benny Wong       pthread_cond_signal(&(pComponentPrivate->StateChangeCondition));
3482eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    }
3483eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
3484eced958917cca059f5e7222a83a44adc4e259c67Benny Wong       return OMX_ErrorUndefined;
3485eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    }
3486eced958917cca059f5e7222a83a44adc4e259c67Benny Wong
3487eced958917cca059f5e7222a83a44adc4e259c67Benny Wong    return eError;
3488eced958917cca059f5e7222a83a44adc4e259c67Benny Wong}
34890db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong
34900db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong/* ========================================================================== */
34910db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong/**
34920db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong * @SignalIfAllBuffersAreReturned() This function send signals if OMX returned all buffers to app
34930db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong *
34940db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong * @param AACENC_COMPONENT_PRIVATE *pComponentPrivate
34950db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong *
34960db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong * @pre None
34970db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong *
34980db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong * @post None
34990db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong *
35000db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong * @return None
35010db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong*/
35020db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong/* ========================================================================== */
35030db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dongvoid SignalIfAllBuffersAreReturned(AACENC_COMPONENT_PRIVATE *pComponentPrivate)
35040db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong{
35050db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong        pthread_mutex_lock(&bufferReturned_mutex);
35060db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong        if ((pComponentPrivate->EmptythisbufferCount == pComponentPrivate->EmptybufferdoneCount) &&
35070db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            (pComponentPrivate->FillthisbufferCount ==   pComponentPrivate->FillbufferdoneCount)) {
35080db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            pthread_cond_broadcast(&bufferReturned_condition);
35090db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong            LOGI("Sending pthread signal that OMX has returned all buffers to app");
35100db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong        }
35110db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong        pthread_mutex_unlock(&bufferReturned_mutex);
35120db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong}
35130db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong
35140db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong/* ====================================================================== */
35150db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong/*@AACENC_IncrementBufferCounterByOne() This function is used by the component
35160db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong * to atomically increment some input or output buffer counter
35170db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong *
35180db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong * @param mutex pointer to mutex for synchronizing the value change on
35190db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong *              the counter
35200db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong * @param counter the buffer counter to be incremented
35210db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong *
35220db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong * @post the buffer counter's value will be incremented by one.
35230db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong * @return None
35240db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong */
35250db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong/* ====================================================================== */
35260db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dongvoid AACENC_IncrementBufferCounterByOne(pthread_mutex_t* mutex, OMX_U32 *counter)
35270db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong{
35280db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong    pthread_mutex_lock(mutex);
35290db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong    (*counter)++;
35300db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong    pthread_mutex_unlock(mutex);
35310db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong}
35320db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong
35330db3b90dbc46ddaa275f66c94c0c963b6cbd535eJames Dong
3534