3 * Copyright (C) Texas Instruments - http://www.ti.com/
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 /* =============================================================================
22 * Texas Instruments OMAP (TM) Platform Software
23 * (c) Copyright Texas Instruments, Incorporated. All Rights Reserved.
25 * Use of this software is controlled by the terms and conditions found
26 * in the license agreement under which this software has been supplied.
27 * =========================================================================== */
29 * @file OMX_G729Dec_ComponentThread.c
31 * This file implements OMX Component for G729 decoder that
32 * is fully compliant with the OMX Audio specification .
34 * @path $(OMAPSW_MPU)\linux\audio\src\openmax_il\g729_dec\src
38 /* -----------------------------------------------------------------------------
41 *! ===================================
42 *! Date Author(s) Version Description
43 *! --------- ------------------- ------- ---------------------------------
44 *! 03-Jan-2007 A.Donjon 0.1 Code update for G729 DECODER
47 * ================================================================================= */
49 /* ------compilation control switches -------------------------*/
50 /****************************************************************
52 ****************************************************************/
53 /* ----- system and platform files ----------------------------*/
64 #include <sys/select.h>
69 /*-------program files ----------------------------------------*/
70 #include "OMX_G729Dec_Utils.h"
71 #include "OMX_G729Decoder.h"
72 #include "OMX_G729Dec_ComponentThread.h"
74 #ifdef RESOURCE_MANAGER_ENABLED
75 #include <ResourceManagerProxyAPI.h>
77 #ifdef __PERF_INSTRUMENTATION__
81 /****************************************************************
82 * EXTERNAL REFERENCES NOTE : only use if not found in header file
83 ****************************************************************/
84 /*--------data declarations -----------------------------------*/
85 /*--------function prototypes ---------------------------------*/
87 /****************************************************************
88 * PUBLIC DECLARATIONS Defined here, used elsewhere
89 ****************************************************************/
90 /*--------data declarations -----------------------------------*/
92 /*--------function prototypes ---------------------------------*/
94 /****************************************************************
95 * PRIVATE DECLARATIONS Defined here, used only here
96 ****************************************************************/
97 /*--------data declarations -----------------------------------*/
98 /*--------function prototypes ---------------------------------*/
99 /*--------macros ----------------------------------------------*/
102 void* G729DEC_ComponentThread (void* pThreadData)
109 OMX_ERRORTYPE eError = OMX_ErrorNone;
110 G729DEC_COMPONENT_PRIVATE* pComponentPrivate = (G729DEC_COMPONENT_PRIVATE*)pThreadData;
111 OMX_COMPONENTTYPE *pHandle = pComponentPrivate->pHandle;
112 OMX_BUFFERHEADERTYPE *pBufHeader = NULL;
115 G729DEC_DPRINT("OMX_G729Dec_ComponentThread:%d\n",__LINE__);
116 #ifdef __PERF_INSTRUMENTATION__
117 pComponentPrivate->pPERFcomp = PERF_Create(PERF_FOURCC('7', '2', '9', 'E'),
118 PERF_ModuleComponent |
119 PERF_ModuleAudioDecode);
121 fdmax = pComponentPrivate->cmdPipe[0];
123 if (pComponentPrivate->dataPipe[0] > fdmax) {
124 fdmax = pComponentPrivate->dataPipe[0];
129 FD_SET (pComponentPrivate->cmdPipe[0], &rfds);
130 FD_SET (pComponentPrivate->dataPipe[0], &rfds);
137 sigaddset (&set, SIGALRM);
138 status = pselect (fdmax+1, &rfds, NULL, NULL, &tv, &set);
142 G729DEC_DPRINT("%d : bIsStopping = %d\n",__LINE__,
143 (int)pComponentPrivate->bIsStopping);
145 G729DEC_DPRINT("%d : lcml_nOpBuf = %d\n",__LINE__,
146 (int)pComponentPrivate->lcml_nOpBuf);
148 G729DEC_DPRINT("%d : lcml_nIpBuf = %d\n",__LINE__,
149 (int)pComponentPrivate->lcml_nIpBuf);
150 G729DEC_DPRINT("%d : app_nBuf = %d\n",__LINE__,
151 (int)pComponentPrivate->app_nBuf);
153 if (pComponentPrivate->bIsStopping == 1) {
154 G729DEC_DPRINT("%d:G729ComponentThread \n",__LINE__);
156 G729DEC_DPRINT("%d:G729ComponentThread \n",__LINE__);
157 if(eError != OMX_ErrorNone) {
158 G729DEC_DPRINT("%d: Error Occurred in Codec Stop..\n",__LINE__);
161 pComponentPrivate->bIsStopping = 0;
162 pComponentPrivate->lcml_nOpBuf = 0;
163 pComponentPrivate->lcml_nIpBuf = 0;
164 pComponentPrivate->app_nBuf = 0;
165 pComponentPrivate->num_Op_Issued = 0;
166 pComponentPrivate->num_Sent_Ip_Buff = 0;
167 pComponentPrivate->num_Reclaimed_Op_Buff = 0;
168 pComponentPrivate->bIsEOFSent = 0;
170 G729DEC_DPRINT("%d:G729ComponentThread \n",__LINE__);
171 if (pComponentPrivate->curState != OMX_StateIdle) {
172 G729DEC_DPRINT("%d:G729AComponentThread \n",__LINE__);
176 G729DEC_DPRINT ("%d :: Component Time Out !!!!!!!!!!!! \n",__LINE__);
178 } else if (-1 == status) {
180 G729DEC_EPRINT ("%d :: Error in Select\n", __LINE__);
181 pComponentPrivate->cbInfo.EventHandler (
183 pHandle->pApplicationPrivate,
184 OMX_EventError,OMX_ErrorInsufficientResources,0,
185 "Error from COmponent Thread in select");
186 eError = OMX_ErrorInsufficientResources;
189 else if ((FD_ISSET (pComponentPrivate->dataPipe[0], &rfds))){
190 G729DEC_DPRINT ("%d :: DATA pipe is set in Component Thread\n",__LINE__);
191 ret = read(pComponentPrivate->dataPipe[0], &pBufHeader, sizeof(pBufHeader));
193 G729DEC_DPRINT ("%d :: Error while reading from the pipe\n",__LINE__);
195 eError = G729DECHandleDataBuf_FromApp (pBufHeader,pComponentPrivate);
196 if (eError != OMX_ErrorNone) {
197 G729DEC_DPRINT ("%d :: Error From G729DECHandleDataBuf_FromApp\n", __LINE__);
202 else if (FD_ISSET (pComponentPrivate->cmdPipe[0], &rfds)) {
203 /* Do not accept any command when the component is stopping */
204 G729DEC_DPRINT ("%d :: CMD pipe is set in Component Thread\n",__LINE__);
205 nRet = G729DECHandleCommand (pComponentPrivate);
206 if (nRet == EXIT_COMPONENT_THRD) {
207 G729DEC_DPRINT ("Exiting from Component thread\n");
208 G729DEC_CleanupInitParams(pHandle);
209 if(eError != OMX_ErrorNone) {
210 G729DEC_DPRINT("%d :: Function G729Dec_FreeCompResources returned\
214 G729DEC_DPRINT("%d :: ARM Side Resources Have Been Freed\n",__LINE__);
215 pComponentPrivate->curState = OMX_StateLoaded;
216 if (pComponentPrivate->bPreempted == 0) {
217 pComponentPrivate->cbInfo.EventHandler(
218 pHandle, pHandle->pApplicationPrivate,
219 OMX_EventCmdComplete,
220 OMX_ErrorNone,pComponentPrivate->curState, NULL);
223 pComponentPrivate->cbInfo.EventHandler(
224 pHandle, pHandle->pApplicationPrivate,
226 OMX_ErrorResourcesLost,pComponentPrivate->curState, NULL);
227 pComponentPrivate->bPreempted = 0;
235 G729DEC_DPRINT("%d::Exiting ComponentThread\n",__LINE__);
236 return (void*)eError;