Home | History | Annotate | Download | only in src
      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 #ifdef ANDROID
     79 #include <utils/threads.h>
     80 #include <linux/prctl.h>
     81 #endif
     82 
     83 #include "OMX_Mp3Dec_Utils.h"
     84 
     85 /* ================================================================================= * */
     86 /**
     87 * @fn MP3DEC_ComponentThread() This is component thread that keeps listening for
     88 * commands or event/messages/buffers from application or from LCML.
     89 *
     90 * @param pThreadData This is thread argument.
     91 *
     92 * @pre          None
     93 *
     94 * @post         None
     95 *
     96 *  @return      OMX_ErrorNone = Always
     97 *
     98 *  @see         None
     99 */
    100 /* ================================================================================ * */
    101 void* MP3DEC_ComponentThread (void* pThreadData)
    102 {
    103     int status;
    104     struct timespec tv;
    105     int fdmax;
    106     fd_set rfds;
    107     OMX_U32 nRet;
    108     OMX_ERRORTYPE eError = OMX_ErrorNone;
    109     MP3DEC_COMPONENT_PRIVATE* pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE*)pThreadData;
    110     OMX_COMPONENTTYPE *pHandle = pComponentPrivate->pHandle;
    111 
    112 #ifdef ANDROID
    113     setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO);
    114     prctl(PR_SET_NAME, (unsigned long)"MP3Component", 0, 0, 0);
    115 #endif
    116 
    117     OMX_PRINT1(pComponentPrivate->dbg, ":: Entering ComponentThread \n");
    118 
    119 #ifdef __PERF_INSTRUMENTATION__
    120     pComponentPrivate->pPERFcomp = PERF_Create(PERF_FOURCC('M', 'P', '3',' '),
    121                                                PERF_ModuleComponent |
    122                                                PERF_ModuleAudioDecode);
    123 #endif
    124 
    125     fdmax = pComponentPrivate->cmdPipe[0];
    126 
    127     if (pComponentPrivate->dataPipe[0] > fdmax) {
    128         fdmax = pComponentPrivate->dataPipe[0];
    129     }
    130 
    131     while (1) {
    132         FD_ZERO (&rfds);
    133         FD_SET (pComponentPrivate->cmdPipe[0], &rfds);
    134         FD_SET (pComponentPrivate->dataPipe[0], &rfds);
    135         tv.tv_sec = 1;
    136         tv.tv_nsec = 0;
    137 
    138 #ifndef UNDER_CE
    139         sigset_t set;
    140         sigemptyset (&set);
    141         sigaddset (&set, SIGALRM);
    142         status = pselect (fdmax+1, &rfds, NULL, NULL, &tv, &set);
    143 #else
    144         status = select (fdmax+1, &rfds, NULL, NULL, &tv);
    145 #endif
    146 
    147         if (pComponentPrivate->bExitCompThrd == 1) {
    148             OMX_PRINT1(pComponentPrivate->dbg, ":: Comp Thrd Exiting here...\n");
    149             goto EXIT;
    150         }
    151 
    152 
    153 
    154         if (0 == status) {
    155             OMX_PRSTATE2(pComponentPrivate->dbg, "\n\n\n!!!!!  Component Time Out !!!!!!!!!!!! \n");
    156             OMX_PRSTATE2(pComponentPrivate->dbg, "Current State: %d \n", pComponentPrivate->curState);
    157 
    158             OMX_PRDSP2(pComponentPrivate->dbg, "%d:: lcml_nCntOp = %lu\n",__LINE__,pComponentPrivate->lcml_nCntOp);
    159             OMX_PRDSP2(pComponentPrivate->dbg, "%d : lcml_nCntIp = %lu\n",__LINE__,pComponentPrivate->lcml_nCntIp);
    160             OMX_PRDSP2(pComponentPrivate->dbg, "%d : lcml_nCntIpRes = %lu\n",__LINE__,pComponentPrivate->lcml_nCntIpRes);
    161             OMX_PRDSP2(pComponentPrivate->dbg, "%d :: lcml_nCntOpReceived = %lu\n",__LINE__,pComponentPrivate->lcml_nCntOpReceived);
    162 
    163             if (pComponentPrivate->bExitCompThrd == 1) {
    164                 OMX_ERROR4(pComponentPrivate->dbg, ":: Comp Thrd Exiting here...\n");
    165                 goto EXIT;
    166             }
    167 
    168 
    169         } else if (-1 == status) {
    170             OMX_ERROR4(pComponentPrivate->dbg, ":: Error in Select\n");
    171             pComponentPrivate->cbInfo.EventHandler (pHandle,
    172                                                     pHandle->pApplicationPrivate,
    173                                                     OMX_EventError,
    174                                                     OMX_ErrorInsufficientResources,
    175                                                     OMX_TI_ErrorSevere,
    176                                                     "Error from COmponent Thread in select");
    177             eError = OMX_ErrorInsufficientResources;
    178 
    179         } else if ((FD_ISSET (pComponentPrivate->dataPipe[0], &rfds))) {
    180             int ret;
    181             OMX_BUFFERHEADERTYPE *pBufHeader = NULL;
    182 
    183             OMX_PRCOMM2(pComponentPrivate->dbg, ":: DATA pipe is set in Component Thread\n");
    184             ret = read(pComponentPrivate->dataPipe[0], &pBufHeader, sizeof(pBufHeader));
    185             if (ret == -1) {
    186                 OMX_ERROR2(pComponentPrivate->dbg, ":: Error while reading from the pipe\n");
    187             }
    188 
    189             eError = MP3DEC_HandleDataBuf_FromApp (pBufHeader,pComponentPrivate);
    190             if (eError != OMX_ErrorNone) {
    191                 OMX_ERROR2(pComponentPrivate->dbg, ":: Error From HandleDataBuf_FromApp\n");
    192                 break;
    193             }
    194         } else if (FD_ISSET (pComponentPrivate->cmdPipe[0], &rfds)) {
    195             OMX_PRCOMM2(pComponentPrivate->dbg, ":: CMD pipe is set in Component Thread\n");
    196             nRet = MP3DEC_HandleCommand (pComponentPrivate);
    197             if (nRet == EXIT_COMPONENT_THRD) {
    198                 OMX_PRDSP2(pComponentPrivate->dbg, "Exiting from Component thread\n");
    199                 MP3DEC_CleanupInitParams(pHandle);
    200                 OMX_PRSTATE2(pComponentPrivate->dbg, "****************** Component State Set to Loaded\n\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, pHandle->pApplicationPrivate,
    208                                                            OMX_EventCmdComplete,
    209                                                            OMX_ErrorNone,pComponentPrivate->curState,
    210                                                            NULL);
    211                 }else{
    212                     pComponentPrivate->cbInfo.EventHandler(pHandle,
    213                                                            pHandle->pApplicationPrivate,
    214                                                            OMX_EventError,
    215                                                            OMX_ErrorResourcesLost,
    216                                                            OMX_TI_ErrorMajor,
    217                                                            NULL);
    218                     pComponentPrivate->bPreempted = 0;
    219                 }
    220             }
    221         }
    222     }
    223 EXIT:
    224 
    225     pComponentPrivate->bCompThreadStarted = 0;
    226 
    227 
    228 #ifdef __PERF_INSTRUMENTATION__
    229     PERF_Done(pComponentPrivate->pPERFcomp);
    230 #endif
    231 
    232     OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting ComponentThread \n");
    233     return (void*)eError;
    234 }
    235