OMX_WbAmrDec_ComponentThread.c revision 00f4c8bed7990ebaff8e20bd13b5dbdacbe22c29
1 2/* 3 * Copyright (C) Texas Instruments - http://www.ti.com/ 4 * 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. 9 * 10 * 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. 15 * 16 * 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 20 */ 21/* ============================================================================== 22 * Texas Instruments OMAP (TM) Platform Software 23 * (c) Copyright Texas Instruments, Incorporated. All Rights Reserved. 24 * 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 * ============================================================================ */ 28/** 29 * @file OMX_WbAmrDec_ComponentThread.c 30 * 31 * This file implements OMX Component for WBMAR decoder that 32 * is fully compliant with the OMX Audio specification 1.0. 33 * 34 * @path $(CSLPATH)\ 35 * 36 * @rev 0.1 37 */ 38/* ---------------------------------------------------------------------------- 39 *! 40 *! Revision History 41 *! =================================== 42 *! 10-Sept-2005 mf: Initial Version. Change required per OMAPSWxxxxxxxxx 43 *! to provide _________________. 44 *! 45 * ============================================================================= */ 46 47 48/* ------compilation control switches -------------------------*/ 49/**************************************************************** 50 * INCLUDE FILES 51 ****************************************************************/ 52/* ----- system and platform files ----------------------------*/ 53#ifdef UNDER_CE 54#include <windows.h> 55#else 56#include <wchar.h> 57#include <unistd.h> 58#include <dbapi.h> 59#include <string.h> 60#include <fcntl.h> 61#include <stdlib.h> 62#include <stdio.h> 63#include <errno.h> 64#include <sys/time.h> 65#include <signal.h> 66#endif 67#include "OMX_WbAmrDec_Utils.h" 68#include "OMX_WbAmrDecoder.h" 69#include "OMX_WbAmrDec_ComponentThread.h" 70 71/* ================================================================================= */ 72/** 73 * @fn WBAMR_DEC_ComponentThread() Component thread 74 * 75 * @see OMX_ComponentThread.h 76 */ 77/* ================================================================================ */ 78 79void* WBAMR_DEC_ComponentThread (void* pThreadData) 80{ 81 OMX_S16 status; 82 struct timespec tv; 83 OMX_S16 fdmax; 84 fd_set rfds; 85 OMX_U32 nRet; 86 OMX_ERRORTYPE eError = OMX_ErrorNone; 87 WBAMR_DEC_COMPONENT_PRIVATE* pComponentPrivate = (WBAMR_DEC_COMPONENT_PRIVATE*)pThreadData; 88 OMX_COMPONENTTYPE *pHandle = pComponentPrivate->pHandle; 89 OMX_BUFFERHEADERTYPE *pBufHeader = NULL; 90 ssize_t ret; 91 92 OMX_PRINT1(pComponentPrivate->dbg, "Entering\n"); 93 94#ifdef __PERF_INSTRUMENTATION__ 95 pComponentPrivate->pPERFcomp = PERF_Create(PERF_FOURCC('W', 'B', '_', 'D'), 96 PERF_ModuleComponent | 97 PERF_ModuleAudioDecode); 98#endif 99 100 fdmax = pComponentPrivate->cmdPipe[0]; 101 102 if (pComponentPrivate->dataPipe[0] > fdmax) { 103 fdmax = pComponentPrivate->dataPipe[0]; 104 } 105 106 while (1) { 107 FD_ZERO (&rfds); 108 FD_SET (pComponentPrivate->cmdPipe[0], &rfds); 109 FD_SET (pComponentPrivate->dataPipe[0], &rfds); 110 111 tv.tv_sec = 1; 112 tv.tv_nsec = 0; 113 114 OMX_PRINT1(pComponentPrivate->dbg, "AmrComponentThread \n"); 115#ifndef UNDER_CE 116 sigset_t set; 117 sigemptyset (&set); 118 sigaddset (&set, SIGALRM); 119 status = pselect (fdmax+1, &rfds, NULL, NULL, &tv, &set); 120#else 121 status = select (fdmax+1, &rfds, NULL, NULL, &tv); 122#endif 123 124 if (pComponentPrivate->bIsStopping == 1) { 125 OMX_ERROR4(pComponentPrivate->dbg, "Comp Thrd Exiting here...\n"); 126 goto EXIT; 127 } 128 if (0 == status) { 129 130 OMX_PRSTATE2(pComponentPrivate->dbg, "bIsStopping = %ld\n", 131 pComponentPrivate->bIsStopping); 132 133 OMX_PRBUFFER2(pComponentPrivate->dbg, "lcml_nOpBuf = %ld\n", 134 pComponentPrivate->lcml_nOpBuf); 135 136 OMX_PRBUFFER2(pComponentPrivate->dbg, "lcml_nIpBuf = %ld\n", 137 pComponentPrivate->lcml_nIpBuf); 138 OMX_PRBUFFER2(pComponentPrivate->dbg, "app_nBuf = %ld\n", 139 pComponentPrivate->app_nBuf); 140 141 if (pComponentPrivate->bIsStopping == 1) { 142 143 pComponentPrivate->bIsStopping = 0; 144 pComponentPrivate->lcml_nOpBuf = 0; 145 pComponentPrivate->lcml_nIpBuf = 0; 146 pComponentPrivate->app_nBuf = 0; 147 pComponentPrivate->num_Reclaimed_Op_Buff = 0; 148 149 OMX_PRINT1(pComponentPrivate->dbg, "AmrComponentThread \n"); 150 if (pComponentPrivate->curState != OMX_StateIdle) { 151 OMX_PRINT1(pComponentPrivate->dbg, "AmrComponentThread \n"); 152 goto EXIT; 153 } 154 } 155 OMX_ERROR2(pComponentPrivate->dbg,"Component Time Out !!!!!!!!!!!! \n"); 156 } else if (-1 == status) { 157 OMX_ERROR4(pComponentPrivate->dbg, "Error in Select\n"); 158 pComponentPrivate->cbInfo.EventHandler (pHandle, 159 pHandle->pApplicationPrivate, 160 OMX_EventError, 161 OMX_ErrorInsufficientResources, 162 OMX_TI_ErrorSevere, 163 "Error from Component Thread in select"); 164 eError = OMX_ErrorInsufficientResources; 165 break; 166 167 } else if (FD_ISSET (pComponentPrivate->dataPipe[0], &rfds)) { 168 OMX_PRCOMM2(pComponentPrivate->dbg, "DATA pipe is set in Component Thread\n"); 169 ret = read(pComponentPrivate->dataPipe[0], &pBufHeader, sizeof(pBufHeader)); 170 if (ret == -1) { 171 OMX_ERROR4(pComponentPrivate->dbg, "Error while reading from the pipe\n"); 172 } 173 eError = WBAMR_DEC_HandleDataBuf_FromApp (pBufHeader,pComponentPrivate); 174 if (eError != OMX_ErrorNone) { 175 OMX_ERROR2(pComponentPrivate->dbg, "Error From WBAMR_DEC_HandleDataBuf_FromApp\n"); 176 break; 177 } 178 } 179 else if (FD_ISSET (pComponentPrivate->cmdPipe[0], &rfds)) { 180 /* Do not accept any command when the component is stopping */ 181 OMX_PRCOMM2(pComponentPrivate->dbg, "CMD pipe is set in Component Thread\n"); 182 nRet = WBAMR_DEC_HandleCommand (pComponentPrivate); 183 if (nRet == WBAMR_DEC_EXIT_COMPONENT_THRD) { 184 OMX_PRINT1(pComponentPrivate->dbg, "Exiting from Component thread\n"); 185 186 if(eError != OMX_ErrorNone) { 187 OMX_ERROR4(pComponentPrivate->dbg, "Function Mp3Dec_FreeCompResources returned\ 188 error\n"); 189 goto EXIT; 190 } 191 OMX_PRBUFFER2(pComponentPrivate->dbg, "ARM Side Resources Have Been Freed\n"); 192 193 pComponentPrivate->curState = OMX_StateLoaded; 194#ifdef __PERF_INSTRUMENTATION__ 195 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundaryCleanup); 196#endif 197 if (pComponentPrivate->bPreempted == 0) { 198 pComponentPrivate->cbInfo.EventHandler(pHandle, 199 pHandle->pApplicationPrivate, 200 OMX_EventCmdComplete, 201 OMX_ErrorNone, 202 pComponentPrivate->curState, 203 NULL); 204 } 205 else { 206 pComponentPrivate->cbInfo.EventHandler(pHandle, 207 pHandle->pApplicationPrivate, 208 OMX_EventError, 209 OMX_ErrorResourcesLost, 210 OMX_TI_ErrorMajor, 211 NULL); 212 pComponentPrivate->bPreempted = 0; 213 } 214 215 } 216 } 217 } 218 EXIT: 219#ifdef __PERF_INSTRUMENTATION__ 220 PERF_Done(pComponentPrivate->pPERFcomp); 221#endif 222 OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n"); 223 return (void*)eError; 224} 225