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#ifdef ANDROID 68#include <sys/resource.h> 69#include <utils/threads.h> 70#include <sys/prctl.h> 71#endif 72#include "OMX_WbAmrDec_Utils.h" 73#include "OMX_WbAmrDecoder.h" 74#include "OMX_WbAmrDec_ComponentThread.h" 75 76/* ================================================================================= */ 77/** 78 * @fn WBAMR_DEC_ComponentThread() Component thread 79 * 80 * @see OMX_ComponentThread.h 81 */ 82/* ================================================================================ */ 83 84void* WBAMR_DEC_ComponentThread (void* pThreadData) 85{ 86 OMX_S16 status; 87 struct timespec tv; 88 OMX_S16 fdmax; 89 fd_set rfds; 90 OMX_U32 nRet; 91 OMX_ERRORTYPE eError = OMX_ErrorNone; 92 WBAMR_DEC_COMPONENT_PRIVATE* pComponentPrivate = (WBAMR_DEC_COMPONENT_PRIVATE*)pThreadData; 93 OMX_COMPONENTTYPE *pHandle = pComponentPrivate->pHandle; 94 OMX_BUFFERHEADERTYPE *pBufHeader = NULL; 95 ssize_t ret; 96 97#ifdef ANDROID 98 setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO); 99 prctl(PR_SET_NAME, (unsigned long)"WBAMRComponent", 0, 0, 0); 100#endif 101 102 OMX_PRINT1(pComponentPrivate->dbg, "Entering\n"); 103 104#ifdef __PERF_INSTRUMENTATION__ 105 pComponentPrivate->pPERFcomp = PERF_Create(PERF_FOURCC('W', 'B', '_', 'D'), 106 PERF_ModuleComponent | 107 PERF_ModuleAudioDecode); 108#endif 109 110 fdmax = pComponentPrivate->cmdPipe[0]; 111 112 if (pComponentPrivate->dataPipe[0] > fdmax) { 113 fdmax = pComponentPrivate->dataPipe[0]; 114 } 115 116 while (1) { 117 FD_ZERO (&rfds); 118 FD_SET (pComponentPrivate->cmdPipe[0], &rfds); 119 FD_SET (pComponentPrivate->dataPipe[0], &rfds); 120 121 tv.tv_sec = 1; 122 tv.tv_nsec = 0; 123 124 OMX_PRINT1(pComponentPrivate->dbg, "AmrComponentThread \n"); 125#ifndef UNDER_CE 126 sigset_t set; 127 sigemptyset (&set); 128 sigaddset (&set, SIGALRM); 129 status = pselect (fdmax+1, &rfds, NULL, NULL, &tv, &set); 130#else 131 status = select (fdmax+1, &rfds, NULL, NULL, &tv); 132#endif 133 134 if (pComponentPrivate->bIsStopping == 1) { 135 OMX_ERROR4(pComponentPrivate->dbg, "Comp Thrd Exiting here...\n"); 136 goto EXIT; 137 } 138 if (0 == status) { 139 140 OMX_PRSTATE2(pComponentPrivate->dbg, "bIsStopping = %ld\n", 141 pComponentPrivate->bIsStopping); 142 143 OMX_PRBUFFER2(pComponentPrivate->dbg, "lcml_nOpBuf = %ld\n", 144 pComponentPrivate->lcml_nOpBuf); 145 146 OMX_PRBUFFER2(pComponentPrivate->dbg, "lcml_nIpBuf = %ld\n", 147 pComponentPrivate->lcml_nIpBuf); 148 OMX_PRBUFFER2(pComponentPrivate->dbg, "app_nBuf = %ld\n", 149 pComponentPrivate->app_nBuf); 150 151 if (pComponentPrivate->bIsStopping == 1) { 152 153 pComponentPrivate->bIsStopping = 0; 154 pComponentPrivate->lcml_nOpBuf = 0; 155 pComponentPrivate->lcml_nIpBuf = 0; 156 pComponentPrivate->app_nBuf = 0; 157 pComponentPrivate->num_Reclaimed_Op_Buff = 0; 158 159 OMX_PRINT1(pComponentPrivate->dbg, "AmrComponentThread \n"); 160 if (pComponentPrivate->curState != OMX_StateIdle) { 161 OMX_PRINT1(pComponentPrivate->dbg, "AmrComponentThread \n"); 162 goto EXIT; 163 } 164 } 165 OMX_PRINT2(pComponentPrivate->dbg,"Component Time Out !!!!!!!!!!!! \n"); 166 } else if (-1 == status) { 167 OMX_ERROR4(pComponentPrivate->dbg, "Error in Select\n"); 168 pComponentPrivate->cbInfo.EventHandler (pHandle, 169 pHandle->pApplicationPrivate, 170 OMX_EventError, 171 OMX_ErrorInsufficientResources, 172 OMX_TI_ErrorSevere, 173 "Error from Component Thread in select"); 174 eError = OMX_ErrorInsufficientResources; 175 176 } else if (FD_ISSET (pComponentPrivate->dataPipe[0], &rfds)) { 177 OMX_PRCOMM2(pComponentPrivate->dbg, "DATA pipe is set in Component Thread\n"); 178 ret = read(pComponentPrivate->dataPipe[0], &pBufHeader, sizeof(pBufHeader)); 179 if (ret == -1) { 180 OMX_ERROR4(pComponentPrivate->dbg, "Error while reading from the pipe\n"); 181 } 182 eError = WBAMR_DEC_HandleDataBuf_FromApp (pBufHeader,pComponentPrivate); 183 if (eError != OMX_ErrorNone) { 184 OMX_ERROR2(pComponentPrivate->dbg, "Error From WBAMR_DEC_HandleDataBuf_FromApp\n"); 185 break; 186 } 187 } 188 else if (FD_ISSET (pComponentPrivate->cmdPipe[0], &rfds)) { 189 /* Do not accept any command when the component is stopping */ 190 OMX_PRCOMM2(pComponentPrivate->dbg, "CMD pipe is set in Component Thread\n"); 191 nRet = WBAMR_DEC_HandleCommand (pComponentPrivate); 192 if (nRet == WBAMR_DEC_EXIT_COMPONENT_THRD) { 193 OMX_PRINT1(pComponentPrivate->dbg, "Exiting from Component thread\n"); 194 195 if(eError != OMX_ErrorNone) { 196 OMX_ERROR4(pComponentPrivate->dbg, "Function Mp3Dec_FreeCompResources returned\ 197 error\n"); 198 goto EXIT; 199 } 200 OMX_PRBUFFER2(pComponentPrivate->dbg, "ARM Side Resources Have Been Freed\n"); 201 202 pComponentPrivate->curState = OMX_StateLoaded; 203#ifdef __PERF_INSTRUMENTATION__ 204 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundaryCleanup); 205#endif 206 if (pComponentPrivate->bPreempted == 0) { 207 pComponentPrivate->cbInfo.EventHandler(pHandle, 208 pHandle->pApplicationPrivate, 209 OMX_EventCmdComplete, 210 OMX_ErrorNone, 211 pComponentPrivate->curState, 212 NULL); 213 } 214 else { 215 pComponentPrivate->cbInfo.EventHandler(pHandle, 216 pHandle->pApplicationPrivate, 217 OMX_EventError, 218 OMX_ErrorResourcesLost, 219 OMX_TI_ErrorMajor, 220 NULL); 221 pComponentPrivate->bPreempted = 0; 222 } 223 224 } 225 } 226 } 227 EXIT: 228#ifdef __PERF_INSTRUMENTATION__ 229 PERF_Done(pComponentPrivate->pPERFcomp); 230#endif 231 OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n"); 232 return (void*)eError; 233} 234