3 * Copyright (C) Texas Instruments - http://www.ti.com/
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.
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.
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
21 /* =============================================================================
22 * Texas Instruments OMAP(TM) Platform Software
23 * (c) Copyright Texas Instruments, Incorporated. All Rights Reserved.
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 * =========================================================================== */
29 * @file OMX_VideoEnc_Thread.c
31 * This file implements OMX Component for MPEG-4 encoder that
32 * is fully compliant with the OMX specification 1.5.
34 * @path $(CSLPATH)\src
38 /* -------------------------------------------------------------------------- */
39 /* =============================================================================
42 *! ================================================================
44 *! 02-Feb-2006 mf: Revisions appear in reverse chronological order;
45 *! that is, newest first. The date format is dd-Mon-yyyy.
46 * =========================================================================== */
49 /* ------compilation control switches ----------------------------------------*/
50 /******************************************************************************
52 *******************************************************************************/
53 /* ----- system and platform files -------------------------------------------*/
59 #define _XOPEN_SOURCE 600
62 #include <sys/select.h>
73 /*------- Program Header Files -----------------------------------------------*/
74 #include "OMX_VideoEnc_Utils.h"
76 /******************************************************************************
77 * EXTERNAL REFERENCES NOTE : only use if not found in header file
78 *******************************************************************************/
79 /*--------data declarations --------------------------------------------------*/
81 /*--------function prototypes ------------------------------------------------*/
83 /******************************************************************************
84 * PUBLIC DECLARATIONS Defined here, used elsewhere
85 *******************************************************************************/
86 /*--------data declarations --------------------------------------------------*/
88 /*--------function prototypes ------------------------------------------------*/
90 /******************************************************************************
91 * PRIVATE DECLARATIONS Defined here, used only here
92 *******************************************************************************/
93 /*--------data declarations --------------------------------------------------*/
95 /*--------macro definitions --------------------------------------------------*/
97 /*--------function prototypes ------------------------------------------------*/
99 /*----------------------------------------------------------------------------*/
101 * OMX_VideoEnc_Thread()
103 * Called by VIDENC_Start_ComponentThread function.
107 * @retval OMX_ErrorNone success, ready to roll
108 * OMX_ErrorInsufficientResources if the malloc fails
110 /*----------------------------------------------------------------------------*/
111 void* OMX_VIDENC_Thread (void* pThreadData)
116 OMX_ERRORTYPE eError = OMX_ErrorNone;
117 OMX_COMMANDTYPE eCmd = -1;
120 OMX_PTR pCmdData = NULL;
121 VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
122 LCML_DSP_INTERFACE* pLcmlHandle = NULL;
127 eError = OMX_ErrorBadParameter;
128 goto OMX_CONF_CMD_BAIL;
131 pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)pThreadData;
132 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
134 #ifdef __PERF_INSTRUMENTATION__
135 pComponentPrivate->pPERFcomp = PERF_Create(PERF_FOURCC('V', 'E', ' ', 'T'),
136 PERF_ModuleComponent |
137 PERF_ModuleVideoEncode);
140 /** Looking for highest number of file descriptor
141 for pipes inorder to put in select loop */
143 fdmax = pComponentPrivate->nCmdPipe[0];
145 if (pComponentPrivate->nFree_oPipe[0] > fdmax)
147 fdmax = pComponentPrivate->nFree_oPipe[0];
150 if (pComponentPrivate->nFilled_iPipe[0] > fdmax)
152 fdmax = pComponentPrivate->nFilled_iPipe[0];
158 FD_SET (pComponentPrivate->nCmdPipe[0], &rfds);
159 FD_SET (pComponentPrivate->nFree_oPipe[0], &rfds);
160 FD_SET (pComponentPrivate->nFilled_iPipe[0], &rfds);
163 sigaddset(&set,SIGALRM);
164 status = pselect(fdmax+1, &rfds, NULL, NULL, NULL,&set);
168 OMX_TRACE2(pComponentPrivate->dbg, "pselect() = 0\n");
175 else if (-1 == status)
177 if (pComponentPrivate->eState != OMX_StateLoaded)
179 OMX_TRACE3(pComponentPrivate->dbg, "select() error.\n");
180 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, OMX_EventError, OMX_ErrorHardware, 0, NULL);
182 /*OMX_VIDENC_SET_ERROR_BAIL(eError, OMX_ErrorHardware, pComponentPrivate);*/
183 eError = OMX_ErrorHardware;
184 OMX_ERROR5(pComponentPrivate->dbg, "*Fatal Error : %x\n", eError);
185 OMX_VIDENC_HandleError(pComponentPrivate, eError);
189 if (FD_ISSET(pComponentPrivate->nCmdPipe[0], &rfds))
191 nRet = read(pComponentPrivate->nCmdPipe[0],
196 OMX_PRCOMM4(pComponentPrivate->dbg, "Error while reading from cmdPipe\n");
197 OMX_VIDENC_SET_ERROR_BAIL(eError,
202 #ifdef __PERF_INSTRUMENTATION__
203 PERF_ReceivedCommand(pComponentPrivate->pPERFcomp,
204 eCmd, 0, PERF_ModuleLLMM);
206 if (eCmd == (OMX_COMMANDTYPE)-1)
208 OMX_PRCOMM2(pComponentPrivate->dbg, "Received thread close command.\n");
209 OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorNone);
212 if (eCmd == OMX_CommandMarkBuffer)
214 nRet = read(pComponentPrivate->nCmdDataPipe[0],
219 OMX_PRCOMM4(pComponentPrivate->dbg, "Error while reading from cmdDataPipe\n");
220 OMX_VIDENC_SET_ERROR_BAIL(eError,
227 nRet = read(pComponentPrivate->nCmdDataPipe[0],
232 OMX_PRCOMM4(pComponentPrivate->dbg, "Error while reading from cmdDataPipe\n");
233 OMX_VIDENC_SET_ERROR_BAIL(eError,
239 #ifdef __PERF_INSTRUMENTATION__
240 PERF_ReceivedCommand(pComponentPrivate->pPERFcomp,
242 (eCmd == OMX_CommandMarkBuffer) ? ((OMX_U32) pCmdData) : nParam1,
248 case OMX_CommandStateSet :
249 OMX_PRSTATE2(pComponentPrivate->dbg, "Enters OMX_VIDENC_HandleCommandStateSet\n");
250 eError = OMX_VIDENC_HandleCommandStateSet(pComponentPrivate,
252 OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
253 OMX_PRSTATE2(pComponentPrivate->dbg, "Exits OMX_VIDENC_HandleCommandStateSet\n");
255 case OMX_CommandFlush :
256 OMX_PRSTATE2(pComponentPrivate->dbg, "Enters OMX_VIDENC_HandleCommandFlush\n");
257 eError = OMX_VIDENC_HandleCommandFlush(pComponentPrivate,
260 OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
261 OMX_PRSTATE2(pComponentPrivate->dbg, "Exits OMX_VIDENC_HandleCommandFlush\n");
263 case OMX_CommandPortDisable :
264 OMX_PRSTATE2(pComponentPrivate->dbg, "Enters OMX_VIDENC_HandleCommandDisablePort\n");
265 eError = OMX_VIDENC_HandleCommandDisablePort(pComponentPrivate,
267 OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
268 OMX_PRSTATE2(pComponentPrivate->dbg, "Exits OMX_VIDENC_HandleCommandDisablePort\n");
270 case OMX_CommandPortEnable :
271 OMX_PRSTATE2(pComponentPrivate->dbg, "Enters OMX_VIDENC_HandleCommandDisablePort\n");
272 eError = OMX_VIDENC_HandleCommandEnablePort(pComponentPrivate,
274 OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
275 OMX_PRSTATE2(pComponentPrivate->dbg, "Exits OMX_VIDENC_HandleCommandDisablePort\n");
277 case OMX_CommandMarkBuffer :
278 if (!pComponentPrivate->pMarkBuf)
280 pComponentPrivate->pMarkBuf = (OMX_MARKTYPE*)(pCmdData);
284 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
292 if ((FD_ISSET(pComponentPrivate->nFilled_iPipe[0], &rfds)) &&
293 (pComponentPrivate->eState != OMX_StatePause &&
294 pComponentPrivate->eState != OMX_StateIdle &&
295 pComponentPrivate->eState != OMX_StateLoaded))
297 OMX_PRBUFFER1(pComponentPrivate->dbg, "Enters OMX_VIDENC_Process_FilledInBuf\n");
298 eError = OMX_VIDENC_Process_FilledInBuf(pComponentPrivate);
299 if (eError != OMX_ErrorNone)
301 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
306 OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
308 OMX_PRBUFFER1(pComponentPrivate->dbg, "Exits OMX_VIDENC_Process_FilledInBuf\n");
311 if (FD_ISSET(pComponentPrivate->nFree_oPipe[0], &rfds) &&
312 (pComponentPrivate->eState!= OMX_StatePause &&
313 pComponentPrivate->eState != OMX_StateIdle &&
314 pComponentPrivate->eState != OMX_StateLoaded))
316 OMX_PRBUFFER1(pComponentPrivate->dbg, "Enters OMX_VIDENC_Process_FreeOutBuf\n");
317 eError = OMX_VIDENC_Process_FreeOutBuf(pComponentPrivate);
318 if (eError != OMX_ErrorNone)
320 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
325 OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
327 OMX_PRBUFFER1(pComponentPrivate->dbg, "Exits OMX_VIDENC_Process_FreeOutBuf\n");
334 #ifdef __PERF_INSTRUMENTATION__
335 if (pComponentPrivate)
336 PERF_Done(pComponentPrivate->pPERFcomp);
338 if (pComponentPrivate)
339 OMX_PRINT2(pComponentPrivate->dbg, "Component Thread Exits\n");
340 return (void*)eError;