OMX_Mp3Dec_CompThread.c revision eaaadaf5ebb5e352e2ed4a12714f5d2363da0dcd
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_Mp3Dec_CompThread.c 30* 31* This file implements various utilitiy functions for various activities 32* like handling command from application, callback from LCML etc. 33* 34* @path $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\mp3_dec\src 35* 36* @rev 1.0 37*/ 38/* ---------------------------------------------------------------------------- 39*! 40*! Revision History 41*! =================================== 42*! 21-sept-2006 bk: updated some review findings for alpha release 43*! 24-Aug-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests some more 44*! 18-July-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests validated for few cases 45*! This is newest file 46* =========================================================================== */ 47/* ------compilation control switches -------------------------*/ 48/**************************************************************** 49* INCLUDE FILES 50****************************************************************/ 51/* ----- system and platform files ----------------------------*/ 52 53 54 55#ifdef UNDER_CE 56#include <windows.h> 57#include <oaf_osal.h> 58#include <omx_core.h> 59#include <stdlib.h> 60#else 61#include <wchar.h> 62#include <unistd.h> 63#include <sys/types.h> 64#include <sys/wait.h> 65#include <sys/types.h> 66#include <sys/stat.h> 67#include <dlfcn.h> 68#include <sys/select.h> 69#include <memory.h> 70#include <fcntl.h> 71#include <signal.h> 72#endif 73 74#include <dbapi.h> 75#include <string.h> 76#include <stdio.h> 77 78#include "OMX_Mp3Dec_Utils.h" 79 80/* ================================================================================= * */ 81/** 82* @fn MP3DEC_ComponentThread() This is component thread that keeps listening for 83* commands or event/messages/buffers from application or from LCML. 84* 85* @param pThreadData This is thread argument. 86* 87* @pre None 88* 89* @post None 90* 91* @return OMX_ErrorNone = Always 92* 93* @see None 94*/ 95/* ================================================================================ * */ 96void* MP3DEC_ComponentThread (void* pThreadData) 97{ 98 int status; 99 struct timespec tv; 100 int fdmax; 101 fd_set rfds; 102 OMX_U32 nRet; 103 OMX_ERRORTYPE eError = OMX_ErrorNone; 104 MP3DEC_COMPONENT_PRIVATE* pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE*)pThreadData; 105 OMX_COMPONENTTYPE *pHandle = pComponentPrivate->pHandle; 106 107 OMX_PRINT1(pComponentPrivate->dbg, ":: Entering ComponentThread \n"); 108 109#ifdef __PERF_INSTRUMENTATION__ 110 pComponentPrivate->pPERFcomp = PERF_Create(PERF_FOURCC('M', 'P', '3',' '), 111 PERF_ModuleComponent | 112 PERF_ModuleAudioDecode); 113#endif 114 115 fdmax = pComponentPrivate->cmdPipe[0]; 116 117 if (pComponentPrivate->dataPipe[0] > fdmax) { 118 fdmax = pComponentPrivate->dataPipe[0]; 119 } 120 121 while (1) { 122 FD_ZERO (&rfds); 123 FD_SET (pComponentPrivate->cmdPipe[0], &rfds); 124 FD_SET (pComponentPrivate->dataPipe[0], &rfds); 125 tv.tv_sec = 1; 126 tv.tv_nsec = 0; 127 128#ifndef UNDER_CE 129 sigset_t set; 130 sigemptyset (&set); 131 sigaddset (&set, SIGALRM); 132 status = pselect (fdmax+1, &rfds, NULL, NULL, &tv, &set); 133#else 134 status = select (fdmax+1, &rfds, NULL, NULL, &tv); 135#endif 136 137 if (pComponentPrivate->bExitCompThrd == 1) { 138 OMX_PRINT1(pComponentPrivate->dbg, ":: Comp Thrd Exiting here...\n"); 139 goto EXIT; 140 } 141 142 143 144 if (0 == status) { 145 OMX_PRSTATE2(pComponentPrivate->dbg, "\n\n\n!!!!! Component Time Out !!!!!!!!!!!! \n"); 146 OMX_PRSTATE2(pComponentPrivate->dbg, "Current State: %d \n", pComponentPrivate->curState); 147 148 OMX_PRDSP2(pComponentPrivate->dbg, "%d:: lcml_nCntOp = %lu\n",__LINE__,pComponentPrivate->lcml_nCntOp); 149 OMX_PRDSP2(pComponentPrivate->dbg, "%d : lcml_nCntIp = %lu\n",__LINE__,pComponentPrivate->lcml_nCntIp); 150 OMX_PRDSP2(pComponentPrivate->dbg, "%d : lcml_nCntIpRes = %lu\n",__LINE__,pComponentPrivate->lcml_nCntIpRes); 151 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: lcml_nCntOpReceived = %lu\n",__LINE__,pComponentPrivate->lcml_nCntOpReceived); 152 153 if (pComponentPrivate->bExitCompThrd == 1) { 154 OMX_ERROR4(pComponentPrivate->dbg, ":: Comp Thrd Exiting here...\n"); 155 goto EXIT; 156 } 157 158 159 } else if (-1 == status) { 160 OMX_ERROR4(pComponentPrivate->dbg, ":: Error in Select\n"); 161 pComponentPrivate->cbInfo.EventHandler (pHandle, 162 pHandle->pApplicationPrivate, 163 OMX_EventError, 164 OMX_ErrorInsufficientResources, 165 OMX_TI_ErrorSevere, 166 "Error from COmponent Thread in select"); 167 eError = OMX_ErrorInsufficientResources; 168 break; 169 170 } else if ((FD_ISSET (pComponentPrivate->dataPipe[0], &rfds))) { 171 int ret; 172 OMX_BUFFERHEADERTYPE *pBufHeader = NULL; 173 174 OMX_PRCOMM2(pComponentPrivate->dbg, ":: DATA pipe is set in Component Thread\n"); 175 ret = read(pComponentPrivate->dataPipe[0], &pBufHeader, sizeof(pBufHeader)); 176 if (ret == -1) { 177 OMX_ERROR2(pComponentPrivate->dbg, ":: Error while reading from the pipe\n"); 178 } 179 180 eError = MP3DEC_HandleDataBuf_FromApp (pBufHeader,pComponentPrivate); 181 if (eError != OMX_ErrorNone) { 182 OMX_ERROR2(pComponentPrivate->dbg, ":: Error From HandleDataBuf_FromApp\n"); 183 break; 184 } 185 } else if (FD_ISSET (pComponentPrivate->cmdPipe[0], &rfds)) { 186 OMX_PRCOMM2(pComponentPrivate->dbg, ":: CMD pipe is set in Component Thread\n"); 187 nRet = MP3DEC_HandleCommand (pComponentPrivate); 188 if (nRet == EXIT_COMPONENT_THRD) { 189 OMX_PRDSP2(pComponentPrivate->dbg, "Exiting from Component thread\n"); 190 MP3DEC_CleanupInitParams(pHandle); 191 OMX_PRSTATE2(pComponentPrivate->dbg, "****************** Component State Set to Loaded\n\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, pHandle->pApplicationPrivate, 199 OMX_EventCmdComplete, 200 OMX_ErrorNone,pComponentPrivate->curState, 201 NULL); 202 }else{ 203 pComponentPrivate->cbInfo.EventHandler(pHandle, 204 pHandle->pApplicationPrivate, 205 OMX_EventError, 206 OMX_ErrorResourcesLost, 207 OMX_TI_ErrorMajor, 208 NULL); 209 pComponentPrivate->bPreempted = 0; 210 } 211 } 212 } 213 } 214EXIT: 215 216 pComponentPrivate->bCompThreadStarted = 0; 217 218 219#ifdef __PERF_INSTRUMENTATION__ 220 PERF_Done(pComponentPrivate->pPERFcomp); 221#endif 222 223 OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting ComponentThread \n"); 224 return (void*)eError; 225} 226