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_G711Dec_ComponentThread.c 30 * 31 * This file implements OMX Component for PCM decoder that 32 * is fully compliant with the OMX Audio specification . 33 * 34 * @path $(CSLPATH)\ 35 * 36 * @rev 0.1 37 */ 38/* ----------------------------------------------------------------------------*/ 39 40/* ------compilation control switches -------------------------*/ 41/**************************************************************** 42 * INCLUDE FILES 43 ****************************************************************/ 44/* ----- system and platform files ----------------------------*/ 45#ifdef UNDER_CE 46#include <windows.h> 47#else 48#include <unistd.h> 49#include <dbapi.h> 50#include <string.h> 51#include <fcntl.h> 52#include <stdlib.h> 53#include <stdio.h> 54#include <errno.h> 55#include <sys/time.h> 56#include <signal.h> 57#endif 58#include "OMX_G711Dec_Utils.h" 59#ifdef RESOURCE_MANAGER_ENABLED 60#include <ResourceManagerProxyAPI.h> 61#endif 62 63void* ComponentThread (void* pThreadData) 64{ 65 OMX_S16 status = 0; 66 struct timespec tv; 67 OMX_S16 fdmax = 0; 68 fd_set rfds; 69 OMX_U32 nRet = 0; 70 OMX_ERRORTYPE eError = OMX_ErrorNone; 71 G711DEC_COMPONENT_PRIVATE* pComponentPrivate = (G711DEC_COMPONENT_PRIVATE*)pThreadData; 72 OMX_COMPONENTTYPE *pHandle = pComponentPrivate->pHandle; 73 OMX_BUFFERHEADERTYPE *pBufHeader = NULL; 74 ssize_t ret = 0; 75 76 G711DEC_DPRINT("OMX_G711Dec_ComponentThread:%d\n",__LINE__); 77 78 fdmax = pComponentPrivate->cmdPipe[0]; 79 80 if (pComponentPrivate->dataPipe[0] > fdmax) { 81 fdmax = pComponentPrivate->dataPipe[0]; 82 } 83 84 while (1) { 85 FD_ZERO (&rfds); 86 FD_SET (pComponentPrivate->cmdPipe[0], &rfds); 87 FD_SET (pComponentPrivate->dataPipe[0], &rfds); 88 tv.tv_sec = 1; 89 tv.tv_nsec = 0; 90 91 92#ifndef UNDER_CE 93 sigset_t set; 94 sigemptyset (&set); 95 sigaddset (&set, SIGALRM); 96 status = pselect (fdmax+1, &rfds, NULL, NULL, &tv, &set); 97#else 98 status = select (fdmax+1, &rfds, NULL, NULL, &tv); 99#endif 100 101 if (0 == status) { 102 if (pComponentPrivate->bIsStopping == 1) { 103 pComponentPrivate->bIsStopping = 0; 104 pComponentPrivate->lcml_nOpBuf = 0; 105 pComponentPrivate->lcml_nIpBuf = 0; 106 pComponentPrivate->app_nBuf = 0; 107 pComponentPrivate->num_Op_Issued = 0; 108 pComponentPrivate->num_Sent_Ip_Buff = 0; 109 pComponentPrivate->num_Reclaimed_Op_Buff = 0; 110 pComponentPrivate->bIsEOFSent = 0; 111 112 if (pComponentPrivate->curState != OMX_StateIdle) { 113 goto EXIT; 114 } 115 } 116 G711DEC_DPRINT ("%d :: Component Time Out !!!!!!!!!!!! \n",__LINE__); 117 } else if (-1 == status) { 118 G711DEC_DPRINT ("%d :: Error in Select\n", __LINE__); 119 pComponentPrivate->cbInfo.EventHandler (pHandle, pHandle->pApplicationPrivate, 120 OMX_EventError, 121 OMX_ErrorInsufficientResources,0, 122 "Error from COmponent Thread in select"); 123 eError = OMX_ErrorInsufficientResources; 124 125 } else if (FD_ISSET(pComponentPrivate->dataPipe[0], &rfds)){ 126 G711DEC_DPRINT ("%d :: DATA pipe is set in Component Thread\n",__LINE__); 127 ret = read(pComponentPrivate->dataPipe[0], &pBufHeader, sizeof(pBufHeader)); 128 129 if (ret == -1) { 130 G711DEC_DPRINT ("%d :: Error while reading from the pipe\n",__LINE__); 131 } 132 133 eError = G711DECHandleDataBuf_FromApp (pBufHeader,pComponentPrivate); 134 135 if (eError != OMX_ErrorNone) { 136 G711DEC_DPRINT ("%d :: Error From G711DECHandleDataBuf_FromApp\n"); 137 break; 138 } 139 } 140 else if (FD_ISSET (pComponentPrivate->cmdPipe[0], &rfds)) { 141 /* Do not accept any command when the component is stopping */ 142 G711DEC_DPRINT ("%d :: CMD pipe is set in Component Thread\n",__LINE__); 143 nRet = G711DECHandleCommand (pComponentPrivate); 144 if (nRet == EXIT_COMPONENT_THRD) { 145 G711DEC_DPRINT ("Exiting from Component thread\n"); 146 G711DEC_CleanupInitParams(pHandle); 147 if(eError != OMX_ErrorNone) { 148 G711DEC_DPRINT("%d :: Function G711Dec_FreeCompResources returned\ 149 error\n",__LINE__); 150 goto EXIT; 151 } 152 G711DEC_DPRINT("%d :: ARM Side Resources Have Been Freed\n",__LINE__); 153 154 pComponentPrivate->curState = OMX_StateLoaded; 155 pComponentPrivate->cbInfo.EventHandler( pHandle, 156 pHandle->pApplicationPrivate, 157 OMX_EventCmdComplete, 158 OMX_ErrorNone, 159 pComponentPrivate->curState, 160 NULL); 161 } 162 } 163 } 164 EXIT: 165 G711DEC_DPRINT("%d::Exiting ComponentThread\n",__LINE__); 166 return (void*)eError; 167} 168