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_G726Dec_CompThread.c 30 * 31 * This file implements the component thread functionality that receives 32 * commands and buffers from application and LCML. 33 * 34 * @path $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\g726_dec\src 35 * 36 * @rev 1.0 37 */ 38 /* ---------------------------------------------------------------------------- 39 *! 40 *! Revision History 41 *! =================================== 42 *! This is newest file 43 * =========================================================================== */ 44 /* ------compilation control switches -------------------------*/ 45 /**************************************************************** 46 * INCLUDE FILES 47 ****************************************************************/ 48 /* ----- system and platform files ----------------------------*/ 49 50 #ifdef UNDER_CE 51 #include <windows.h> 52 #include <oaf_osal.h> 53 #include <omx_core.h> 54 #include <stdlib.h> 55 #else 56 #include <unistd.h> 57 #include <sys/types.h> 58 #include <sys/types.h> 59 #include <sys/stat.h> 60 #include <dlfcn.h> 61 #include <sys/select.h> 62 #include <malloc.h> 63 #include <memory.h> 64 #include <fcntl.h> 65 #include <signal.h> 66 #include <sys/select.h> 67 #endif 68 69 #include <dbapi.h> 70 #include <string.h> 71 #include <stdio.h> 72 73 #include "OMX_G726Dec_Utils.h" 74 75 /* ================================================================================= * */ 76 /** 77 * @fn G726DEC_ComponentThread() This is component thread that keeps listening for 78 * commands or event/messages/buffers from application or from LCML. 79 * 80 * @param pThreadData This is thread argument. 81 * 82 * @pre None 83 * 84 * @post None 85 * 86 * @return OMX_ErrorNone = Always 87 * 88 * @see None 89 */ 90 /* ================================================================================ * */ 91 void* G726DEC_ComponentThread (void* pThreadData) 92 { 93 int status = 0; 94 struct timespec tv; 95 int fdmax = 0; 96 fd_set rfds; 97 OMX_U32 nRet = 0; 98 OMX_ERRORTYPE eError = OMX_ErrorNone; 99 G726DEC_COMPONENT_PRIVATE* pComponentPrivate = (G726DEC_COMPONENT_PRIVATE*)pThreadData; 100 OMX_COMPONENTTYPE *pHandle = pComponentPrivate->pHandle; 101 102 G726DEC_DPRINT (":: Entering ComponentThread \n"); 103 104 fdmax = pComponentPrivate->cmdPipe[0]; 105 106 if (pComponentPrivate->dataPipe[0] > fdmax) { 107 fdmax = pComponentPrivate->dataPipe[0]; 108 } 109 110 111 while (1) { 112 FD_ZERO (&rfds); 113 FD_SET (pComponentPrivate->cmdPipe[0], &rfds); 114 FD_SET (pComponentPrivate->dataPipe[0], &rfds); 115 tv.tv_sec = 1; 116 tv.tv_nsec = 0; 117 118 #ifndef UNDER_CE 119 sigset_t set; 120 sigemptyset (&set); 121 sigaddset (&set, SIGALRM); 122 status = pselect (fdmax+1, &rfds, NULL, NULL, &tv, &set); 123 #else 124 status = select (fdmax+1, &rfds, NULL, NULL, &tv); 125 #endif 126 127 if (pComponentPrivate->bExitCompThrd == 1) { 128 G726DEC_DPRINT(":: Comp Thrd Exiting here...\n"); 129 goto EXIT; 130 } 131 132 if (0 == status) { 133 G726DEC_DPRINT("\n\n\n!!!!! Component Time Out !!!!!!!!!!!! \n"); 134 if (pComponentPrivate->bExitCompThrd == 1) { 135 G726DEC_EPRINT(":: Comp Thrd Exiting here...\n"); 136 goto EXIT; 137 } 138 139 } else if (-1 == status) { 140 G726DEC_DPRINT (":: Error in Select\n"); 141 pComponentPrivate->cbInfo.EventHandler ( 142 pHandle,pHandle->pApplicationPrivate, 143 OMX_EventError,OMX_ErrorInsufficientResources, 0, 144 "Error from COmponent Thread in select"); 145 eError = OMX_ErrorInsufficientResources; 146 147 } else if ((FD_ISSET (pComponentPrivate->dataPipe[0], &rfds))) { 148 149 int ret; 150 OMX_BUFFERHEADERTYPE *pBufHeader = NULL; 151 152 G726DEC_DPRINT (":: DATA pipe is set in Component Thread\n"); 153 ret = read(pComponentPrivate->dataPipe[0], &pBufHeader, sizeof(pBufHeader)); 154 if (ret == -1) { 155 G726DEC_DPRINT (":: Error while reading from the pipe\n"); 156 } 157 158 eError = G726DEC_HandleDataBuf_FromApp (pBufHeader,pComponentPrivate); 159 if (eError != OMX_ErrorNone) { 160 G726DEC_DPRINT (":: Error From HandleDataBuf_FromApp\n"); 161 break; 162 } 163 } else if (FD_ISSET (pComponentPrivate->cmdPipe[0], &rfds)) { 164 G726DEC_DPRINT (":: CMD pipe is set in Component Thread\n"); 165 166 nRet = G726DEC_HandleCommand (pComponentPrivate); 167 if (nRet == EXIT_COMPONENT_THRD) { 168 G726DEC_DPRINT ("Exiting from Component thread\n"); 169 G726DEC_CleanupInitParams(pHandle); 170 G726DEC_STATEPRINT("****************** Component State Set to Loaded\n\n"); 171 172 pComponentPrivate->curState = OMX_StateLoaded; 173 174 if (pComponentPrivate->bPreempted == 0) { 175 pComponentPrivate->cbInfo.EventHandler( 176 pHandle, pHandle->pApplicationPrivate, 177 OMX_EventCmdComplete, 178 OMX_ErrorNone,pComponentPrivate->curState, NULL); 179 } 180 else { 181 pComponentPrivate->cbInfo.EventHandler( 182 pHandle, pHandle->pApplicationPrivate, 183 OMX_EventError, 184 OMX_ErrorResourcesLost,pComponentPrivate->curState, NULL); 185 pComponentPrivate->bPreempted = 0; 186 } 187 188 } 189 190 } 191 } 192 EXIT: 193 194 pComponentPrivate->bCompThreadStarted = 0; 195 196 G726DEC_DPRINT (":: Exiting ComponentThread \n"); 197 return (void*)eError; 198 } 199