• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 #include "pv_omxcomponent.h"
19 #include "pv_omxdefs.h"
20 #include "oscl_types.h"
21 
22 #if PROXY_INTERFACE
23 #include "omx_proxy_interface.h"
24 #endif
25 
26 
OmxComponentBase()27 OmxComponentBase::OmxComponentBase() :
28         OsclActiveObject(OsclActiveObject::EPriorityNominal, "OMXComponent")
29 {
30     iLogger = PVLogger::GetLoggerObject("OmxComponentBase");
31     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : constructed"));
32 
33     //Flag to call BufferMgmtFunction in the Run() when the component state is executing
34     iBufferExecuteFlag = OMX_FALSE;
35     ipAppPriv = NULL;
36 
37     ipCallbacks = NULL;
38     iCallbackData = NULL;
39     iState = OMX_StateLoaded;
40 
41     ipCoreDescriptor = NULL;
42     iNumInputBuffer = 0;
43 
44     ipFrameDecodeBuffer = NULL;
45     iPartialFrameAssembly = OMX_FALSE;
46     iIsInputBufferEnded = OMX_TRUE;
47     iEndofStream = OMX_FALSE;
48     ipTempInputBuffer = NULL;
49     iTempInputBufferLength = 0;
50 
51     ipTargetComponent = NULL;
52     iTargetMarkData = NULL;
53     iNewInBufferRequired = OMX_TRUE;
54     iNewOutBufRequired = OMX_TRUE;
55 
56     iTempConsumedLength = 0;
57     iOutBufferCount = 0;
58     iCodecReady = OMX_FALSE;
59     ipInputCurrBuffer = NULL;
60     iInputCurrLength = 0;
61     iFrameCount = 0;
62     iStateTransitionFlag = OMX_FALSE;
63     iEndOfFrameFlag = OMX_FALSE;
64     ipInputBuffer = NULL;
65     ipOutputBuffer = NULL;
66     iInputCurrBufferSize = 0;
67 
68     iEosProcessing = OMX_FALSE;
69     iFirstFragment = OMX_FALSE;
70     iResizePending = OMX_FALSE;
71     iFrameTimestamp = 0;
72     iIsFirstOutputFrame = OMX_TRUE;
73     iSilenceInsertionInProgress = OMX_FALSE;
74 
75     iNumPorts = 0;
76     iCompressedFormatPortNum = OMX_PORT_INPUTPORT_INDEX;
77     ipPorts = NULL;
78 
79     //Indicate whether component has been already initialized */
80     iIsInit = OMX_FALSE;
81 
82     iGroupPriority = 0;
83     iGroupID = 0;
84 
85     ipTempOutBufferForPortReconfig = NULL;
86     iSendOutBufferAfterPortReconfigFlag = OMX_FALSE;
87     iSizeOutBufferForPortReconfig = 0;
88 
89     iComponentRoleFlag = OMX_FALSE;
90 
91     ipMark = NULL;
92 
93 }
94 
95 
ConstructBaseComponent(OMX_PTR pAppData)96 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::ConstructBaseComponent(OMX_PTR pAppData)
97 {
98     OSCL_UNUSED_ARG(pAppData);
99     OMX_U32 ii, jj;
100 
101     if (iNumPorts)
102     {
103         if (ipPorts)
104         {
105             oscl_free(ipPorts);
106             ipPorts = NULL;
107         }
108 
109         ipPorts = (ComponentPortType**) oscl_calloc(iNumPorts, sizeof(ComponentPortType*));
110         if (!ipPorts)
111         {
112             return OMX_ErrorInsufficientResources;
113         }
114 
115         for (ii = 0; ii < iNumPorts; ii++)
116         {
117             ipPorts[ii] = (ComponentPortType*) oscl_calloc(1, sizeof(ComponentPortType));
118             if (!ipPorts[ii])
119             {
120                 return OMX_ErrorInsufficientResources;
121             }
122 
123             ipPorts[ii]->TransientState = OMX_StateMax;
124             SetHeader(&ipPorts[ii]->PortParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
125             ipPorts[ii]->PortParam.nPortIndex = ii;
126 
127             /** Allocate and initialize buffer Queue */
128             ipPorts[ii]->pBufferQueue = (QueueType*) oscl_malloc(sizeof(QueueType));
129 
130             if (NULL == ipPorts[ii]->pBufferQueue)
131             {
132                 return OMX_ErrorInsufficientResources;
133             }
134 
135             if (OMX_ErrorNone != QueueInit(ipPorts[ii]->pBufferQueue))
136             {
137                 return OMX_ErrorInsufficientResources;
138             }
139 
140             for (jj = 0; jj < OMX_PORT_NUMBER_FORMATS_SUPPORTED; jj++)
141             {
142                 oscl_memset(&ipPorts[ii]->VideoParam[jj], 0, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
143             }
144         }
145 
146         SetPortFlushFlag(iNumPorts, -1, OMX_FALSE);
147         SetNumBufferFlush(iNumPorts, -1, OMX_FALSE);
148     }
149 
150 
151     iCodecReady = OMX_FALSE;
152     ipCallbacks = NULL;
153     iCallbackData = NULL;
154     iState = OMX_StateLoaded;
155     ipTempInputBuffer = NULL;
156     iTempInputBufferLength = 0;
157     iNumInputBuffer = 0;
158     iPartialFrameAssembly = OMX_FALSE;
159     iEndofStream = OMX_FALSE;
160     iIsInputBufferEnded = OMX_TRUE;
161     iNewOutBufRequired = OMX_TRUE;
162     iEosProcessing = OMX_FALSE;
163     iRepositionFlag = OMX_FALSE;
164     iIsFirstOutputFrame = OMX_TRUE;
165     iMarkPropagate = OMX_FALSE;
166     ipTempOutBufferForPortReconfig = NULL;
167     iSendOutBufferAfterPortReconfigFlag = OMX_FALSE;
168     iSizeOutBufferForPortReconfig = 0;
169     iComponentRoleFlag = OMX_FALSE;
170 
171 
172     /* Initialize the asynchronous command Queue */
173     if (ipCoreDescriptor)
174     {
175         oscl_free(ipCoreDescriptor);
176         ipCoreDescriptor = NULL;
177     }
178 
179     ipCoreDescriptor = (CoreDescriptorType*) oscl_malloc(sizeof(CoreDescriptorType));
180     if (NULL == ipCoreDescriptor)
181     {
182         return OMX_ErrorInsufficientResources;
183     }
184 
185     ipCoreDescriptor->pMessageQueue = NULL;
186     ipCoreDescriptor->pMessageQueue = (QueueType*) oscl_malloc(sizeof(QueueType));
187     if (NULL == ipCoreDescriptor->pMessageQueue)
188     {
189         return OMX_ErrorInsufficientResources;
190     }
191 
192     if (OMX_ErrorNone != QueueInit(ipCoreDescriptor->pMessageQueue))
193     {
194         return OMX_ErrorInsufficientResources;
195     }
196 
197     /** Default parameters setting */
198     iIsInit = OMX_FALSE;
199     iGroupPriority = 0;
200     iGroupID = 0;
201     ipMark = NULL;
202 
203     SetHeader(&iPortTypesParam, sizeof(OMX_PORT_PARAM_TYPE));
204 
205     iOutBufferCount = 0;
206     iStateTransitionFlag = OMX_FALSE;
207     iEndOfFrameFlag = OMX_FALSE;
208     iFirstFragment = OMX_FALSE;
209 
210     //Will be used in case of partial frame assembly
211     ipInputCurrBuffer = NULL;
212     iInputCurrBufferSize = 0;
213     ipAppPriv->CompHandle = &iOmxComponent;
214 
215     return OMX_ErrorNone;
216 }
217 
218 
DestroyBaseComponent()219 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::DestroyBaseComponent()
220 {
221     OMX_U32 ii;
222 
223     /*Deinitialize and free ports semaphores and Queue*/
224     for (ii = 0; ii < iNumPorts; ii++)
225     {
226         if (NULL != ipPorts[ii]->pBufferQueue)
227         {
228             QueueDeinit(ipPorts[ii]->pBufferQueue);
229             oscl_free(ipPorts[ii]->pBufferQueue);
230             ipPorts[ii]->pBufferQueue = NULL;
231         }
232         /*Free port*/
233         if (NULL != ipPorts[ii])
234         {
235             oscl_free(ipPorts[ii]);
236             ipPorts[ii] = NULL;
237         }
238     }
239 
240     if (ipPorts)
241     {
242         oscl_free(ipPorts);
243         ipPorts = NULL;
244     }
245 
246     iState = OMX_StateLoaded;
247 
248     //Free the temp output buffer
249     if (ipTempOutBufferForPortReconfig)
250     {
251         oscl_free(ipTempOutBufferForPortReconfig);
252         ipTempOutBufferForPortReconfig = NULL;
253         iSizeOutBufferForPortReconfig = 0;
254     }
255 
256     if (ipInputCurrBuffer)
257     {
258         oscl_free(ipInputCurrBuffer);
259         ipInputCurrBuffer = NULL;
260         iInputCurrBufferSize = 0;
261     }
262 
263     if (ipTempInputBuffer)
264     {
265         oscl_free(ipTempInputBuffer);
266         ipTempInputBuffer = NULL;
267     }
268 
269     if (NULL != ipCoreDescriptor)
270     {
271 
272         if (NULL != ipCoreDescriptor->pMessageQueue)
273         {
274             /* De-initialize the asynchronous command queue */
275             QueueDeinit(ipCoreDescriptor->pMessageQueue);
276             oscl_free(ipCoreDescriptor->pMessageQueue);
277             ipCoreDescriptor->pMessageQueue = NULL;
278         }
279 
280         oscl_free(ipCoreDescriptor);
281         ipCoreDescriptor = NULL;
282     }
283 
284     return OMX_ErrorNone;
285 }
286 
287 
288 /*********************
289  *
290  * Component verfication routines
291  *
292  **********************/
293 
SetHeader(OMX_PTR aHeader,OMX_U32 aSize)294 OSCL_EXPORT_REF void OmxComponentBase::SetHeader(OMX_PTR aHeader, OMX_U32 aSize)
295 {
296     OMX_VERSIONTYPE* pVersion = (OMX_VERSIONTYPE*)((OMX_STRING) aHeader + sizeof(OMX_U32));
297     *((OMX_U32*) aHeader) = aSize;
298 
299     pVersion->s.nVersionMajor = SPECVERSIONMAJOR;
300     pVersion->s.nVersionMinor = SPECVERSIONMINOR;
301     pVersion->s.nRevision = SPECREVISION;
302     pVersion->s.nStep = SPECSTEP;
303 }
304 
305 
CheckHeader(OMX_PTR aHeader,OMX_U32 aSize)306 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::CheckHeader(OMX_PTR aHeader, OMX_U32 aSize)
307 {
308     OMX_VERSIONTYPE* pVersion = (OMX_VERSIONTYPE*)((OMX_STRING) aHeader + sizeof(OMX_U32));
309 
310     if (NULL == aHeader)
311     {
312         return OMX_ErrorBadParameter;
313     }
314 
315     if (*((OMX_U32*) aHeader) != aSize)
316     {
317         return OMX_ErrorBadParameter;
318     }
319 
320     if (pVersion->s.nVersionMajor != SPECVERSIONMAJOR ||
321             pVersion->s.nVersionMinor != SPECVERSIONMINOR ||
322             pVersion->s.nRevision != SPECREVISION ||
323             pVersion->s.nStep != SPECSTEP)
324     {
325         return OMX_ErrorVersionMismatch;
326     }
327 
328     return OMX_ErrorNone;
329 }
330 
331 
332 /**
333  * This function verify component state and structure header
334  */
ParameterSanityCheck(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_PTR pStructure,OMX_IN size_t size)335 OMX_ERRORTYPE OmxComponentBase::ParameterSanityCheck(
336     OMX_IN  OMX_HANDLETYPE hComponent,
337     OMX_IN  OMX_U32 nPortIndex,
338     OMX_IN  OMX_PTR pStructure,
339     OMX_IN  size_t size)
340 {
341     OSCL_UNUSED_ARG(hComponent);
342     if (iState != OMX_StateLoaded &&
343             iState != OMX_StateWaitForResources)
344     {
345         return OMX_ErrorIncorrectStateOperation;
346     }
347 
348     if (nPortIndex >= iNumPorts)
349     {
350         return OMX_ErrorBadPortIndex;
351     }
352 
353     return CheckHeader(pStructure, size);
354 }
355 
356 /**
357  * Set/Reset Port Flush Flag
358  */
SetPortFlushFlag(OMX_S32 NumPorts,OMX_S32 index,OMX_BOOL value)359 void OmxComponentBase::SetPortFlushFlag(OMX_S32 NumPorts, OMX_S32 index, OMX_BOOL value)
360 {
361     OMX_S32 ii;
362 
363     if (-1 == index)
364     {
365         for (ii = 0; ii < NumPorts; ii++)
366         {
367             ipPorts[ii]->IsPortFlushed = value;
368         }
369     }
370     else
371     {
372         ipPorts[index]->IsPortFlushed = value;
373     }
374 
375 }
376 
377 /**
378  * Set Number of Buffer Flushed with the value Specified
379  */
SetNumBufferFlush(OMX_S32 NumPorts,OMX_S32 index,OMX_S32 value)380 void OmxComponentBase::SetNumBufferFlush(OMX_S32 NumPorts, OMX_S32 index, OMX_S32 value)
381 {
382     OMX_S32 ii;
383 
384     if (-1 == index)
385     {
386         // For all ComponentPort
387         for (ii = 0; ii < NumPorts; ii++)
388         {
389             ipPorts[ii]->NumBufferFlushed = value;
390         }
391     }
392     else
393     {
394         ipPorts[index]->NumBufferFlushed = value;
395     }
396 }
397 
398 
ParseFullAVCFramesIntoNALs(OMX_BUFFERHEADERTYPE * aInputBuffer)399 OSCL_EXPORT_REF OMX_BOOL OmxComponentBase::ParseFullAVCFramesIntoNALs(OMX_BUFFERHEADERTYPE* aInputBuffer)
400 {
401     OSCL_UNUSED_ARG(aInputBuffer);
402 
403     // we should never arrive here if this is not an AVC component, since iOMXComponentUsesFullAVCFrames (which is tested before calling this function)
404     // should only be set for an AVC component
405 
406     OSCL_ASSERT(OMX_FALSE);
407 
408     return OMX_FALSE;
409 }
410 
411 /** This function assembles multiple input buffers into
412     * one frame with the marker flag OMX_BUFFERFLAG_ENDOFFRAME set
413     */
AssemblePartialFrames(OMX_BUFFERHEADERTYPE * aInputBuffer)414 OMX_BOOL OmxComponentBase::AssemblePartialFrames(OMX_BUFFERHEADERTYPE* aInputBuffer)
415 {
416     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AssemblePartialFrames IN"));
417 
418     QueueType* pInputQueue = ipPorts[OMX_PORT_INPUTPORT_INDEX]->pBufferQueue;
419 
420     ComponentPortType* pInPort = ipPorts[OMX_PORT_INPUTPORT_INDEX];
421     OMX_U32 BytesToCopy = 0;
422 
423     ipInputBuffer = aInputBuffer;
424 
425     if (!iPartialFrameAssembly)
426     {
427         if (iNumInputBuffer > 0)
428         {
429             if (ipInputBuffer->nFlags & OMX_BUFFERFLAG_ENDOFFRAME)
430             {
431                 iInputCurrLength = ipInputBuffer->nFilledLen;
432 
433                 //Only applicable for H.264 component
434 #ifdef INSERT_NAL_START_CODE
435                 // this is the case of 1 full NAL in 1 buffer
436                 // if start codes are inserted, skip the start code
437                 iInputCurrLength = ipInputBuffer->nFilledLen - 4;
438                 ipInputBuffer->nOffset += 4;
439 #endif
440                 ipFrameDecodeBuffer = ipInputBuffer->pBuffer + ipInputBuffer->nOffset;
441                 //capture the timestamp to be send to the corresponding output buffer
442                 iFrameTimestamp = ipInputBuffer->nTimeStamp;
443             }
444             else
445             {
446                 iInputCurrLength = 0;
447                 iPartialFrameAssembly = OMX_TRUE;
448                 iFirstFragment = OMX_TRUE;
449                 iFrameTimestamp = ipInputBuffer->nTimeStamp;
450                 ipFrameDecodeBuffer = ipInputCurrBuffer;
451             }
452 
453         }
454         else
455         {
456             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AssemblePartialFrames ERROR"));
457             return OMX_FALSE;
458         }
459 
460     }
461 
462     //Assembling of partial frame will be done based on OMX_BUFFERFLAG_ENDOFFRAME flag marked
463     if (iPartialFrameAssembly)
464     {
465         while (iNumInputBuffer > 0)
466         {
467             if (OMX_FALSE == iFirstFragment)
468             {
469                 /* If the timestamp of curr fragment doesn't match with previous,
470                  * discard the previous fragments & start reconstructing from new
471                  */
472                 if (iFrameTimestamp != ipInputBuffer->nTimeStamp)
473                 {
474                     iInputCurrLength = 0;
475                     iPartialFrameAssembly = OMX_TRUE;
476                     iFirstFragment = OMX_TRUE;
477                     iFrameTimestamp = ipInputBuffer->nTimeStamp;
478                     ipFrameDecodeBuffer = ipInputCurrBuffer;
479 
480                     //Send a stream corrupt callback
481                     OMX_COMPONENTTYPE  *pHandle = &iOmxComponent;
482                     (*(ipCallbacks->EventHandler))
483                     (pHandle,
484                      iCallbackData,
485                      OMX_EventError,
486                      OMX_ErrorStreamCorrupt,
487                      0,
488                      NULL);
489                 }
490             }
491 
492 #ifdef INSERT_NAL_START_CODE
493             else
494             {
495                 // this is the case of a partial NAL in 1 buffer
496                 // this is the first fragment of a nal
497 
498                 // if start codes are inserted, skip the start code
499                 ipInputBuffer->nFilledLen -= 4;
500                 ipInputBuffer->nOffset += 4;
501             }
502 #endif
503 
504             if ((ipInputBuffer->nFlags & OMX_BUFFERFLAG_ENDOFFRAME) != 0)
505             {
506                 break;
507             }
508 
509             // check if the buffer size can take the new piece, or it needs to expand
510             BytesToCopy = ipInputBuffer->nFilledLen;
511 
512             if (iInputCurrBufferSize < (iInputCurrLength + BytesToCopy))
513             {
514                 // allocate new partial frame buffer
515                 OMX_U8* pTempNewBuffer = NULL;
516                 pTempNewBuffer = (OMX_U8*) oscl_malloc(sizeof(OMX_U8) * (iInputCurrLength + BytesToCopy));
517 
518                 // in the event that new buffer cannot be allocated
519                 if (NULL == pTempNewBuffer)
520                 {
521                     // copy into what space is available, and let the decoder complain
522                     BytesToCopy = iInputCurrLength - iInputCurrBufferSize;
523                 }
524                 else
525                 {
526 
527                     // copy contents of the old buffer into the new one
528                     oscl_memcpy(pTempNewBuffer, ipInputCurrBuffer, iInputCurrBufferSize);
529                     // free the old buffer
530                     if (ipInputCurrBuffer)
531                     {
532                         oscl_free(ipInputCurrBuffer);
533                     }
534                     // assign new one
535                     ipInputCurrBuffer = pTempNewBuffer;
536                     iInputCurrBufferSize = (iInputCurrLength + BytesToCopy);
537                     ipFrameDecodeBuffer = ipInputCurrBuffer + iInputCurrLength;
538                 }
539             }
540 
541             iInputCurrLength += BytesToCopy;
542             oscl_memcpy(ipFrameDecodeBuffer, (ipInputBuffer->pBuffer + ipInputBuffer->nOffset), BytesToCopy); // copy buffer data
543             ipFrameDecodeBuffer += BytesToCopy; // move the ptr
544 
545             ipInputBuffer->nFilledLen = 0;
546 
547             ReturnInputBuffer(ipInputBuffer, pInPort);
548             ipInputBuffer = NULL;
549 
550             iFirstFragment = OMX_FALSE;
551 
552             if (iNumInputBuffer > 0)
553             {
554                 ipInputBuffer = (OMX_BUFFERHEADERTYPE*) DeQueue(pInputQueue);
555                 if (NULL == ipInputBuffer)
556                 {
557                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AssemblePartialFrames ERROR DeQueue() returned NULL"));
558                     return OMX_FALSE;
559                 }
560 
561                 if (ipInputBuffer->nFlags & OMX_BUFFERFLAG_EOS)
562                 {
563                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AssemblePartialFrames EndOfStream arrived"));
564                     iEndofStream = OMX_TRUE;
565                 }
566             }
567         }
568 
569         // if we broke out of the while loop because of lack of buffers, then return and wait for more input buffers
570         if (0 == iNumInputBuffer)
571         {
572             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AssemblePartialFrames OUT"));
573             return OMX_FALSE;
574         }
575         else
576         {
577             // we have found the buffer that is the last piece of the frame.
578             // Copy the buffer, but do not release it yet (this will be done after decoding for consistency)
579 
580             BytesToCopy = ipInputBuffer->nFilledLen;
581             // check if the buffer size can take the new piece, or it needs to expand
582             if (iInputCurrBufferSize < (iInputCurrLength + BytesToCopy))
583             {
584                 // allocate new partial frame buffer
585                 OMX_U8* pTempNewBuffer = NULL;
586                 pTempNewBuffer = (OMX_U8*) oscl_malloc(sizeof(OMX_U8) * (iInputCurrLength + BytesToCopy));
587 
588                 // if you cannot allocate new buffer, just copy what data you can
589                 if (NULL == pTempNewBuffer)
590                 {
591                     BytesToCopy = iInputCurrBufferSize - iInputCurrLength;
592                 }
593                 else
594                 {
595 
596                     // copy contents of the old one into new one
597                     oscl_memcpy(pTempNewBuffer, ipInputCurrBuffer, iInputCurrBufferSize);
598                     // free the old buffer
599                     if (ipInputCurrBuffer)
600                     {
601                         oscl_free(ipInputCurrBuffer);
602                     }
603                     // assign new one
604                     ipInputCurrBuffer = pTempNewBuffer;
605                     iInputCurrBufferSize = (iInputCurrLength + BytesToCopy);
606                     ipFrameDecodeBuffer = ipInputCurrBuffer + iInputCurrLength;
607                 }
608             }
609 
610             iInputCurrLength += BytesToCopy;
611             oscl_memcpy(ipFrameDecodeBuffer, (ipInputBuffer->pBuffer + ipInputBuffer->nOffset), BytesToCopy); // copy buffer data
612             ipFrameDecodeBuffer += BytesToCopy; // move the ptr
613 
614             ipFrameDecodeBuffer = ipInputCurrBuffer; // reset the pointer back to beginning of assembly buffer
615             iPartialFrameAssembly = OMX_FALSE; // we have finished with assembling the frame, so this is not needed any more
616         }
617     }
618 
619     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AssemblePartialFrames OUT"));
620     return OMX_TRUE;
621 }
622 
623 
ReturnInputBuffer(OMX_BUFFERHEADERTYPE * pInputBuffer,ComponentPortType * pPort)624 OSCL_EXPORT_REF void OmxComponentBase::ReturnInputBuffer(OMX_BUFFERHEADERTYPE* pInputBuffer, ComponentPortType* pPort)
625 {
626     OSCL_UNUSED_ARG(pPort);
627     OMX_COMPONENTTYPE* pHandle = &iOmxComponent;
628 
629     if (iNumInputBuffer)
630     {
631         iNumInputBuffer--;
632     }
633 
634     //Callback for releasing the input buffer
635     (*(ipCallbacks->EmptyBufferDone))
636     (pHandle, iCallbackData, pInputBuffer);
637 
638 }
639 
640 /**
641  * Returns Output Buffer back to the IL client
642  */
ReturnOutputBuffer(OMX_BUFFERHEADERTYPE * pOutputBuffer,ComponentPortType * pPort)643 OSCL_EXPORT_REF void OmxComponentBase::ReturnOutputBuffer(OMX_BUFFERHEADERTYPE* pOutputBuffer,
644         ComponentPortType *pPort)
645 {
646     OMX_COMPONENTTYPE* pHandle = &iOmxComponent;
647 
648     //Callback for sending back the output buffer
649     (*(ipCallbacks->FillBufferDone))
650     (pHandle, iCallbackData, pOutputBuffer);
651 
652     if (iOutBufferCount)
653     {
654         iOutBufferCount--;
655     }
656 
657     pPort->NumBufferFlushed++;
658     iNewOutBufRequired = OMX_TRUE;
659 }
660 
661 
662 /** Flushes all the buffers under processing by the given port.
663     * This function is called due to a state change of the component, typically
664     * @param PortIndex the ID of the port to be flushed
665     */
666 
FlushPort(OMX_S32 PortIndex)667 OMX_ERRORTYPE OmxComponentBase::FlushPort(OMX_S32 PortIndex)
668 {
669     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FlushPort IN"));
670 
671     OMX_COMPONENTTYPE* pHandle = &iOmxComponent;
672 
673 
674     QueueType* pInputQueue = ipPorts[OMX_PORT_INPUTPORT_INDEX]->pBufferQueue;
675     QueueType* pOutputQueue = ipPorts[OMX_PORT_OUTPUTPORT_INDEX]->pBufferQueue;
676 
677     OMX_BUFFERHEADERTYPE* pOutputBuff;
678     OMX_BUFFERHEADERTYPE* pInputBuff;
679 
680     if (OMX_PORT_INPUTPORT_INDEX == PortIndex || OMX_PORT_ALLPORT_INDEX == PortIndex)
681     {
682         iPartialFrameAssembly = OMX_FALSE;
683 
684         //Release all the input buffers in queue
685         while ((GetQueueNumElem(pInputQueue) > 0))
686         {
687             pInputBuff = (OMX_BUFFERHEADERTYPE*) DeQueue(pInputQueue);
688             if (NULL == pInputBuff)
689             {
690                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FlushPort ERROR DeQueue() returned NULL"));
691                 return OMX_ErrorUndefined;
692             }
693             (*(ipCallbacks->EmptyBufferDone))
694             (pHandle, iCallbackData, pInputBuff);
695             iNumInputBuffer--;
696         }
697 
698         //Release the current buffer that is being processed by the component.
699         if (iNumInputBuffer > 0 && ipInputBuffer && (OMX_FALSE == iIsInputBufferEnded))
700         {
701             (*(ipCallbacks->EmptyBufferDone))
702             (pHandle, iCallbackData, ipInputBuffer);
703             iNumInputBuffer--;
704 
705             iIsInputBufferEnded = OMX_TRUE;
706             iInputCurrLength = 0;
707         }
708     }
709 
710     if (OMX_PORT_OUTPUTPORT_INDEX == PortIndex || OMX_PORT_ALLPORT_INDEX == PortIndex)
711     {
712         //Release the current output buffer if present that is being processed by the component.
713         if ((OMX_FALSE == iNewOutBufRequired) && (iOutBufferCount > 0))
714         {
715             if (ipOutputBuffer)
716             {
717                 (*(ipCallbacks->FillBufferDone))
718                 (pHandle, iCallbackData, ipOutputBuffer);
719                 iOutBufferCount--;
720                 iNewOutBufRequired = OMX_TRUE;
721             }
722         }
723 
724         //Release all other output buffers in queue
725         while ((GetQueueNumElem(pOutputQueue) > 0))
726         {
727             pOutputBuff = (OMX_BUFFERHEADERTYPE*) DeQueue(pOutputQueue);
728             if (NULL == pOutputBuff)
729             {
730                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FlushPort ERROR DeQueue() returned NULL"));
731                 return OMX_ErrorUndefined;
732             }
733 
734             pOutputBuff->nFilledLen = 0;
735             (*(ipCallbacks->FillBufferDone))
736             (pHandle, iCallbackData, pOutputBuff);
737             iOutBufferCount--;
738         }
739 
740     }
741 
742     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FlushPort OUT"));
743     return OMX_ErrorNone;
744 }
745 
746 /**
747  * Disable Single Port
748  */
DisableSinglePort(OMX_U32 PortIndex)749 void OmxComponentBase::DisableSinglePort(OMX_U32 PortIndex)
750 {
751     ipPorts[PortIndex]->PortParam.bEnabled = OMX_FALSE;
752 
753     if (PORT_IS_POPULATED(ipPorts[PortIndex]) && OMX_TRUE == iIsInit)
754     {
755         iStateTransitionFlag = OMX_TRUE;
756         return;
757     }
758 
759     ipPorts[PortIndex]->NumBufferFlushed = 0;
760 }
761 
762 
763 /** Disables the specified port. This function is called due to a request by the IL client
764     * @param PortIndex the ID of the port to be disabled
765     */
DisablePort(OMX_S32 PortIndex)766 OMX_ERRORTYPE OmxComponentBase::DisablePort(OMX_S32 PortIndex)
767 {
768 
769     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DisablePort IN"));
770     OMX_U32 ii;
771 
772     if (-1 == PortIndex)
773     {
774         for (ii = 0; ii < iNumPorts; ii++)
775         {
776             ipPorts[ii]->IsPortFlushed = OMX_TRUE;
777         }
778 
779         /*Flush all ports*/
780         FlushPort(PortIndex);
781 
782         for (ii = 0; ii < iNumPorts; ii++)
783         {
784             ipPorts[ii]->IsPortFlushed = OMX_FALSE;
785         }
786     }
787     else
788     {
789         /*Flush the port specified*/
790         ipPorts[PortIndex]->IsPortFlushed = OMX_TRUE;
791         FlushPort(PortIndex);
792         ipPorts[PortIndex]->IsPortFlushed = OMX_FALSE;
793     }
794 
795     /*Disable ports*/
796     if (PortIndex != -1)
797     {
798         DisableSinglePort(PortIndex);
799     }
800     else
801     {
802         for (ii = 0; ii < iNumPorts; ii++)
803         {
804             DisableSinglePort(ii);
805         }
806     }
807 
808     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DisablePort OUT"));
809 
810     return OMX_ErrorNone;
811 }
812 
813 /**
814  * Enable Single Port
815  */
EnableSinglePort(OMX_U32 PortIndex)816 void OmxComponentBase::EnableSinglePort(OMX_U32 PortIndex)
817 {
818     ipPorts[PortIndex]->PortParam.bEnabled = OMX_TRUE;
819 
820     if (!PORT_IS_POPULATED(ipPorts[PortIndex]) && OMX_TRUE == iIsInit)
821     {
822         iStateTransitionFlag = OMX_TRUE;
823         return;
824     }
825 }
826 
827 /** Enables the specified port. This function is called due to a request by the IL client
828     * @param PortIndex the ID of the port to be enabled
829     */
EnablePort(OMX_S32 PortIndex)830 OMX_ERRORTYPE OmxComponentBase::EnablePort(OMX_S32 PortIndex)
831 {
832     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : EnablePort IN"));
833 
834     OMX_U32 ii;
835 
836     /*Enable port/s*/
837     if (PortIndex != -1)
838     {
839         EnableSinglePort(PortIndex);
840     }
841     else
842     {
843         for (ii = 0; ii < iNumPorts; ii++)
844         {
845             EnableSinglePort(ii);
846         }
847     }
848 
849     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : EnablePort OUT"));
850     return OMX_ErrorNone;
851 }
852 
853 //Not implemented & supported in case of base profile components
854 
TunnelRequest(OMX_IN OMX_HANDLETYPE hComp,OMX_IN OMX_U32 nPort,OMX_IN OMX_HANDLETYPE hTunneledComp,OMX_IN OMX_U32 nTunneledPort,OMX_INOUT OMX_TUNNELSETUPTYPE * pTunnelSetup)855 OMX_ERRORTYPE OmxComponentBase::TunnelRequest(
856     OMX_IN  OMX_HANDLETYPE hComp,
857     OMX_IN  OMX_U32 nPort,
858     OMX_IN  OMX_HANDLETYPE hTunneledComp,
859     OMX_IN  OMX_U32 nTunneledPort,
860     OMX_INOUT  OMX_TUNNELSETUPTYPE* pTunnelSetup)
861 {
862     OSCL_UNUSED_ARG(hComp);
863     OSCL_UNUSED_ARG(nPort);
864     OSCL_UNUSED_ARG(hTunneledComp);
865     OSCL_UNUSED_ARG(nTunneledPort);
866     OSCL_UNUSED_ARG(pTunnelSetup);
867 
868     return OMX_ErrorNotImplemented;
869 }
870 
871 
BaseComponentGetConfig(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nIndex,OMX_INOUT OMX_PTR pComponentConfigStructure)872 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentGetConfig(
873     OMX_IN  OMX_HANDLETYPE hComponent,
874     OMX_IN  OMX_INDEXTYPE nIndex,
875     OMX_INOUT OMX_PTR pComponentConfigStructure)
876 {
877 
878     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
879     OMX_ERRORTYPE Status;
880 
881     if (NULL == pOpenmaxAOType)
882     {
883         return OMX_ErrorBadParameter;
884     }
885 
886     Status = pOpenmaxAOType->GetConfig(hComponent, nIndex, pComponentConfigStructure);
887     return Status;
888 }
889 
890 
891 
GetConfig(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nIndex,OMX_INOUT OMX_PTR pComponentConfigStructure)892 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::GetConfig(
893     OMX_IN  OMX_HANDLETYPE hComponent,
894     OMX_IN  OMX_INDEXTYPE nIndex,
895     OMX_INOUT OMX_PTR pComponentConfigStructure)
896 {
897     OSCL_UNUSED_ARG(hComponent);
898     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : GetConfig IN"));
899 
900     OMX_U32 PortIndex;
901     OMX_CONFIG_INTRAREFRESHVOPTYPE* pVideoIFrame;
902     OMX_CONFIG_FRAMERATETYPE* pFrameRateType;
903     OMX_VIDEO_CONFIG_BITRATETYPE* pConfigBitRateType;
904 
905     if (NULL == pComponentConfigStructure)
906     {
907         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : GetConfig error bad parameter"));
908         return OMX_ErrorBadParameter;
909     }
910 
911     switch (nIndex)
912     {
913         case OMX_IndexConfigVideoIntraVOPRefresh:
914         {
915             pVideoIFrame = (OMX_CONFIG_INTRAREFRESHVOPTYPE*) pComponentConfigStructure;
916             if (pVideoIFrame->nPortIndex != iCompressedFormatPortNum)
917             {
918                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : GetConfig error bad port index for OMX_IndexConfigVideoIntraVOPRefresh"));
919                 return OMX_ErrorBadPortIndex;
920             }
921             PortIndex = pVideoIFrame->nPortIndex;
922             oscl_memcpy(pVideoIFrame, &ipPorts[PortIndex]->VideoIFrame, sizeof(OMX_CONFIG_INTRAREFRESHVOPTYPE));
923             SetHeader(pVideoIFrame, sizeof(OMX_CONFIG_INTRAREFRESHVOPTYPE));
924         }
925         break;
926 
927         case OMX_IndexConfigVideoFramerate:
928         {
929             pFrameRateType = (OMX_CONFIG_FRAMERATETYPE*) pComponentConfigStructure;
930             if (pFrameRateType->nPortIndex != iCompressedFormatPortNum)
931             {
932                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : GetConfig error bad port index for OMX_IndexConfigVideoFramerate"));
933                 return OMX_ErrorBadPortIndex;
934             }
935             PortIndex = pFrameRateType->nPortIndex;
936             oscl_memcpy(pFrameRateType, &ipPorts[PortIndex]->VideoConfigFrameRateType, sizeof(OMX_CONFIG_FRAMERATETYPE));
937             SetHeader(pFrameRateType, sizeof(OMX_CONFIG_FRAMERATETYPE));
938         }
939         break;
940 
941         case OMX_IndexConfigVideoBitrate:
942         {
943             pConfigBitRateType = (OMX_VIDEO_CONFIG_BITRATETYPE*) pComponentConfigStructure;
944             if (pConfigBitRateType->nPortIndex != iCompressedFormatPortNum)
945             {
946                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : GetConfig error bad port index for OMX_IndexConfigVideoBitrate"));
947                 return OMX_ErrorBadPortIndex;
948             }
949             PortIndex = pConfigBitRateType->nPortIndex;
950             oscl_memcpy(pConfigBitRateType, &ipPorts[PortIndex]->VideoConfigBitRateType, sizeof(OMX_VIDEO_CONFIG_BITRATETYPE));
951             SetHeader(pConfigBitRateType, sizeof(OMX_VIDEO_CONFIG_BITRATETYPE));
952         }
953         break;
954         default:
955         {
956             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : GetParameter error Unsupported Index"));
957             return OMX_ErrorUnsupportedIndex;
958         }
959 
960     }
961 
962     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : GetConfig OUT"));
963 
964     return OMX_ErrorNone;
965 }
966 
967 
BaseComponentSetConfig(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nIndex,OMX_IN OMX_PTR pComponentConfigStructure)968 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentSetConfig(
969     OMX_IN  OMX_HANDLETYPE hComponent,
970     OMX_IN  OMX_INDEXTYPE nIndex,
971     OMX_IN  OMX_PTR pComponentConfigStructure)
972 {
973     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
974     OMX_ERRORTYPE Status;
975 
976     if (NULL == pOpenmaxAOType)
977     {
978         return OMX_ErrorBadParameter;
979     }
980 
981     Status = pOpenmaxAOType->SetConfig(hComponent, nIndex, pComponentConfigStructure);
982     return Status;
983 }
984 
985 
SetConfig(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nIndex,OMX_IN OMX_PTR pComponentConfigStructure)986 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::SetConfig(
987     OMX_IN  OMX_HANDLETYPE hComponent,
988     OMX_IN  OMX_INDEXTYPE nIndex,
989     OMX_IN  OMX_PTR pComponentConfigStructure)
990 {
991     OSCL_UNUSED_ARG(hComponent);
992     OSCL_UNUSED_ARG(nIndex);
993     OSCL_UNUSED_ARG(pComponentConfigStructure);
994 
995     return OMX_ErrorNotImplemented;
996 }
997 
998 
BaseComponentGetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_STRING cParameterName,OMX_OUT OMX_INDEXTYPE * pIndexType)999 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentGetExtensionIndex(
1000     OMX_IN  OMX_HANDLETYPE hComponent,
1001     OMX_IN  OMX_STRING cParameterName,
1002     OMX_OUT OMX_INDEXTYPE* pIndexType)
1003 {
1004     OSCL_UNUSED_ARG(hComponent);
1005     OSCL_UNUSED_ARG(cParameterName);
1006     OSCL_UNUSED_ARG(pIndexType);
1007 
1008     return OMX_ErrorNotImplemented;
1009 }
1010 
1011 
BaseComponentGetState(OMX_IN OMX_HANDLETYPE hComponent,OMX_OUT OMX_STATETYPE * pState)1012 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentGetState(
1013     OMX_IN  OMX_HANDLETYPE hComponent,
1014     OMX_OUT OMX_STATETYPE* pState)
1015 {
1016     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
1017 
1018     pOpenmaxAOType->GetState(pState);
1019 
1020     return OMX_ErrorNone;
1021 }
1022 
1023 
GetState(OMX_OUT OMX_STATETYPE * pState)1024 void OmxComponentBase::GetState(OMX_OUT OMX_STATETYPE* pState)
1025 {
1026     *pState = iState;
1027 }
1028 
1029 
BaseComponentGetParameter(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nParamIndex,OMX_INOUT OMX_PTR ComponentParameterStructure)1030 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentGetParameter(
1031     OMX_IN  OMX_HANDLETYPE hComponent,
1032     OMX_IN  OMX_INDEXTYPE nParamIndex,
1033     OMX_INOUT OMX_PTR ComponentParameterStructure)
1034 {
1035 
1036     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
1037     OMX_ERRORTYPE Status;
1038 
1039     if (NULL == pOpenmaxAOType)
1040     {
1041         return OMX_ErrorBadParameter;
1042     }
1043 
1044     Status = pOpenmaxAOType->GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
1045     return Status;
1046 
1047 }
1048 
BaseComponentSetParameter(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nParamIndex,OMX_IN OMX_PTR ComponentParameterStructure)1049 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentSetParameter(
1050     OMX_IN  OMX_HANDLETYPE hComponent,
1051     OMX_IN  OMX_INDEXTYPE nParamIndex,
1052     OMX_IN  OMX_PTR ComponentParameterStructure)
1053 {
1054 
1055     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
1056     OMX_ERRORTYPE Status;
1057 
1058     if (NULL == pOpenmaxAOType)
1059     {
1060         return OMX_ErrorBadParameter;
1061     }
1062 
1063     Status = pOpenmaxAOType->SetParameter(hComponent, nParamIndex, ComponentParameterStructure);
1064 
1065     return Status;
1066 }
1067 
1068 
BaseComponentUseBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_INOUT OMX_BUFFERHEADERTYPE ** ppBufferHdr,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_PTR pAppPrivate,OMX_IN OMX_U32 nSizeBytes,OMX_IN OMX_U8 * pBuffer)1069 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentUseBuffer(
1070     OMX_IN OMX_HANDLETYPE hComponent,
1071     OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
1072     OMX_IN OMX_U32 nPortIndex,
1073     OMX_IN OMX_PTR pAppPrivate,
1074     OMX_IN OMX_U32 nSizeBytes,
1075     OMX_IN OMX_U8* pBuffer)
1076 {
1077     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
1078     OMX_ERRORTYPE Status;
1079 
1080     if (NULL == pOpenmaxAOType)
1081     {
1082         return OMX_ErrorBadParameter;
1083     }
1084 
1085     Status = pOpenmaxAOType->UseBuffer(hComponent, ppBufferHdr, nPortIndex, pAppPrivate, nSizeBytes, pBuffer);
1086 
1087     return Status;
1088 }
1089 
1090 
UseBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_INOUT OMX_BUFFERHEADERTYPE ** ppBufferHdr,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_PTR pAppPrivate,OMX_IN OMX_U32 nSizeBytes,OMX_IN OMX_U8 * pBuffer)1091 OMX_ERRORTYPE OmxComponentBase::UseBuffer(
1092     OMX_IN OMX_HANDLETYPE hComponent,
1093     OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
1094     OMX_IN OMX_U32 nPortIndex,
1095     OMX_IN OMX_PTR pAppPrivate,
1096     OMX_IN OMX_U32 nSizeBytes,
1097     OMX_IN OMX_U8* pBuffer)
1098 {
1099     OSCL_UNUSED_ARG(hComponent);
1100 
1101     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : UseBuffer IN"));
1102     ComponentPortType* pBaseComponentPort;
1103     OMX_U32 ii;
1104 
1105     if (nPortIndex >= iNumPorts)
1106     {
1107         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : UseBuffer error bad port index"));
1108         return OMX_ErrorBadPortIndex;
1109     }
1110 
1111     pBaseComponentPort = ipPorts[nPortIndex];
1112 
1113     if (pBaseComponentPort->TransientState != OMX_StateIdle)
1114     {
1115         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : UseBuffer error incorrect state"));
1116         return OMX_ErrorIncorrectStateTransition;
1117     }
1118 
1119     if (NULL == pBaseComponentPort->pBuffer)
1120     {
1121         pBaseComponentPort->pBuffer = (OMX_BUFFERHEADERTYPE**) oscl_calloc(pBaseComponentPort->PortParam.nBufferCountActual, sizeof(OMX_BUFFERHEADERTYPE*));
1122         if (NULL == pBaseComponentPort->pBuffer)
1123         {
1124             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : UseBuffer error insufficient resources"));
1125             return OMX_ErrorInsufficientResources;
1126         }
1127 
1128         pBaseComponentPort->BufferState = (OMX_U32*) oscl_calloc(pBaseComponentPort->PortParam.nBufferCountActual, sizeof(OMX_U32));
1129         if (NULL == pBaseComponentPort->BufferState)
1130         {
1131             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : UseBuffer error insufficient resources"));
1132             return OMX_ErrorInsufficientResources;
1133         }
1134     }
1135 
1136     for (ii = 0; ii < pBaseComponentPort->PortParam.nBufferCountActual; ii++)
1137     {
1138         if (!(pBaseComponentPort->BufferState[ii] & BUFFER_ALLOCATED) &&
1139                 !(pBaseComponentPort->BufferState[ii] & BUFFER_ASSIGNED))
1140         {
1141             pBaseComponentPort->pBuffer[ii] = (OMX_BUFFERHEADERTYPE*) oscl_malloc(sizeof(OMX_BUFFERHEADERTYPE));
1142             if (NULL == pBaseComponentPort->pBuffer[ii])
1143             {
1144                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : UseBuffer error insufficient resources"));
1145                 return OMX_ErrorInsufficientResources;
1146             }
1147             SetHeader(pBaseComponentPort->pBuffer[ii], sizeof(OMX_BUFFERHEADERTYPE));
1148             pBaseComponentPort->pBuffer[ii]->pBuffer = pBuffer;
1149             pBaseComponentPort->pBuffer[ii]->nAllocLen = nSizeBytes;
1150             pBaseComponentPort->pBuffer[ii]->nFilledLen = 0;
1151             pBaseComponentPort->pBuffer[ii]->nOffset = 0;
1152             pBaseComponentPort->pBuffer[ii]->nFlags = 0;
1153             pBaseComponentPort->pBuffer[ii]->pPlatformPrivate = pBaseComponentPort;
1154             pBaseComponentPort->pBuffer[ii]->pAppPrivate = pAppPrivate;
1155             pBaseComponentPort->pBuffer[ii]->nTickCount = 0;
1156             pBaseComponentPort->pBuffer[ii]->nTimeStamp = 0;
1157             *ppBufferHdr = pBaseComponentPort->pBuffer[ii];
1158             if (OMX_DirInput == pBaseComponentPort->PortParam.eDir)
1159             {
1160                 pBaseComponentPort->pBuffer[ii]->nInputPortIndex = nPortIndex;
1161                 pBaseComponentPort->pBuffer[ii]->nOutputPortIndex = iNumPorts; // here is assigned a non-valid port index
1162             }
1163             else
1164             {
1165                 pBaseComponentPort->pBuffer[ii]->nOutputPortIndex = nPortIndex;
1166                 pBaseComponentPort->pBuffer[ii]->nInputPortIndex = iNumPorts; // here is assigned a non-valid port index
1167             }
1168             pBaseComponentPort->BufferState[ii] |= BUFFER_ASSIGNED;
1169             pBaseComponentPort->BufferState[ii] |= HEADER_ALLOCATED;
1170             pBaseComponentPort->NumAssignedBuffers++;
1171             if (pBaseComponentPort->PortParam.nBufferCountActual == pBaseComponentPort->NumAssignedBuffers)
1172             {
1173                 pBaseComponentPort->PortParam.bPopulated = OMX_TRUE;
1174 
1175                 if (OMX_TRUE == iStateTransitionFlag)
1176                 {
1177                     //Reschedule the AO for a state change (Loaded->Idle) if its pending on buffer allocation
1178                     RunIfNotReady();
1179                     iStateTransitionFlag = OMX_FALSE;
1180                 }
1181             }
1182             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : UseBuffer OUT"));
1183             return OMX_ErrorNone;
1184         }
1185     }
1186 
1187     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : UseBuffer OUT"));
1188     return OMX_ErrorNone;
1189 }
1190 
1191 
BaseComponentAllocateBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_INOUT OMX_BUFFERHEADERTYPE ** pBuffer,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_PTR pAppPrivate,OMX_IN OMX_U32 nSizeBytes)1192 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentAllocateBuffer(
1193     OMX_IN OMX_HANDLETYPE hComponent,
1194     OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
1195     OMX_IN OMX_U32 nPortIndex,
1196     OMX_IN OMX_PTR pAppPrivate,
1197     OMX_IN OMX_U32 nSizeBytes)
1198 {
1199     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
1200     OMX_ERRORTYPE Status;
1201 
1202     if (NULL == pOpenmaxAOType)
1203     {
1204         return OMX_ErrorBadParameter;
1205     }
1206 
1207     Status = pOpenmaxAOType->AllocateBuffer(hComponent, pBuffer, nPortIndex, pAppPrivate, nSizeBytes);
1208 
1209     return Status;
1210 }
1211 
1212 
AllocateBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_INOUT OMX_BUFFERHEADERTYPE ** pBuffer,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_PTR pAppPrivate,OMX_IN OMX_U32 nSizeBytes)1213 OMX_ERRORTYPE OmxComponentBase::AllocateBuffer(
1214     OMX_IN OMX_HANDLETYPE hComponent,
1215     OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
1216     OMX_IN OMX_U32 nPortIndex,
1217     OMX_IN OMX_PTR pAppPrivate,
1218     OMX_IN OMX_U32 nSizeBytes)
1219 {
1220     OSCL_UNUSED_ARG(hComponent);
1221 
1222     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AllocateBuffer IN"));
1223 
1224     ComponentPortType* pBaseComponentPort;
1225     OMX_U32 ii;
1226 
1227     if (nPortIndex >= iNumPorts)
1228     {
1229         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AllocateBuffer error bad port index"));
1230         return OMX_ErrorBadPortIndex;
1231     }
1232 
1233     pBaseComponentPort = ipPorts[nPortIndex];
1234 
1235     if (pBaseComponentPort->TransientState != OMX_StateIdle)
1236     {
1237         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AllocateBuffer error incorrect state"));
1238         return OMX_ErrorIncorrectStateTransition;
1239     }
1240 
1241     if (NULL == pBaseComponentPort->pBuffer)
1242     {
1243         pBaseComponentPort->pBuffer = (OMX_BUFFERHEADERTYPE**) oscl_calloc(pBaseComponentPort->PortParam.nBufferCountActual, sizeof(OMX_BUFFERHEADERTYPE*));
1244         if (NULL == pBaseComponentPort->pBuffer)
1245         {
1246             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AllocateBuffer error insufficient resources"));
1247             return OMX_ErrorInsufficientResources;
1248         }
1249 
1250         pBaseComponentPort->BufferState = (OMX_U32*) oscl_calloc(pBaseComponentPort->PortParam.nBufferCountActual, sizeof(OMX_U32));
1251         if (NULL == pBaseComponentPort->BufferState)
1252         {
1253             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AllocateBuffer error insufficient resources"));
1254             return OMX_ErrorInsufficientResources;
1255         }
1256     }
1257 
1258     for (ii = 0; ii < pBaseComponentPort->PortParam.nBufferCountActual; ii++)
1259     {
1260         if (!(pBaseComponentPort->BufferState[ii] & BUFFER_ALLOCATED) &&
1261                 !(pBaseComponentPort->BufferState[ii] & BUFFER_ASSIGNED))
1262         {
1263             pBaseComponentPort->pBuffer[ii] = (OMX_BUFFERHEADERTYPE*) oscl_malloc(sizeof(OMX_BUFFERHEADERTYPE));
1264             if (NULL == pBaseComponentPort->pBuffer[ii])
1265             {
1266                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AllocateBuffer error insufficient resources"));
1267                 return OMX_ErrorInsufficientResources;
1268             }
1269             SetHeader(pBaseComponentPort->pBuffer[ii], sizeof(OMX_BUFFERHEADERTYPE));
1270             /* allocate the buffer */
1271             pBaseComponentPort->pBuffer[ii]->pBuffer = (OMX_BYTE) oscl_malloc(nSizeBytes);
1272             if (NULL == pBaseComponentPort->pBuffer[ii]->pBuffer)
1273             {
1274                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AllocateBuffer error insufficient resources"));
1275                 return OMX_ErrorInsufficientResources;
1276             }
1277             pBaseComponentPort->pBuffer[ii]->nAllocLen = nSizeBytes;
1278             pBaseComponentPort->pBuffer[ii]->nFlags = 0;
1279             pBaseComponentPort->pBuffer[ii]->pPlatformPrivate = pBaseComponentPort;
1280             pBaseComponentPort->pBuffer[ii]->pAppPrivate = pAppPrivate;
1281             *pBuffer = pBaseComponentPort->pBuffer[ii];
1282             pBaseComponentPort->BufferState[ii] |= BUFFER_ALLOCATED;
1283             pBaseComponentPort->BufferState[ii] |= HEADER_ALLOCATED;
1284 
1285             if (OMX_DirInput == pBaseComponentPort->PortParam.eDir)
1286             {
1287                 pBaseComponentPort->pBuffer[ii]->nInputPortIndex = nPortIndex;
1288                 // here is assigned a non-valid port index
1289                 pBaseComponentPort->pBuffer[ii]->nOutputPortIndex = iNumPorts;
1290             }
1291             else
1292             {
1293                 // here is assigned a non-valid port index
1294                 pBaseComponentPort->pBuffer[ii]->nInputPortIndex = iNumPorts;
1295                 pBaseComponentPort->pBuffer[ii]->nOutputPortIndex = nPortIndex;
1296             }
1297 
1298             pBaseComponentPort->NumAssignedBuffers++;
1299 
1300             if (pBaseComponentPort->PortParam.nBufferCountActual == pBaseComponentPort->NumAssignedBuffers)
1301             {
1302                 pBaseComponentPort->PortParam.bPopulated = OMX_TRUE;
1303 
1304                 if (OMX_TRUE == iStateTransitionFlag)
1305                 {
1306                     //Reschedule the AO for a state change (Loaded->Idle) if its pending on buffer allocation
1307                     RunIfNotReady();
1308                     iStateTransitionFlag = OMX_FALSE;
1309                 }
1310             }
1311 
1312             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AllocateBuffer OUT"));
1313             return OMX_ErrorNone;
1314         }
1315     }
1316 
1317     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : AllocateBuffer OUT"));
1318     return OMX_ErrorInsufficientResources;
1319 }
1320 
BaseComponentFreeBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)1321 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentFreeBuffer(
1322     OMX_IN  OMX_HANDLETYPE hComponent,
1323     OMX_IN  OMX_U32 nPortIndex,
1324     OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
1325 {
1326     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
1327     OMX_ERRORTYPE Status;
1328 
1329     if (NULL == pOpenmaxAOType)
1330     {
1331         return OMX_ErrorBadParameter;
1332     }
1333 
1334     Status = pOpenmaxAOType->FreeBuffer(hComponent, nPortIndex, pBuffer);
1335 
1336     return Status;
1337 }
1338 
1339 
FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)1340 OMX_ERRORTYPE OmxComponentBase::FreeBuffer(
1341     OMX_IN  OMX_HANDLETYPE hComponent,
1342     OMX_IN  OMX_U32 nPortIndex,
1343     OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
1344 {
1345     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FreeBuffer IN"));
1346 
1347     ComponentPortType* pBaseComponentPort;
1348 
1349     OMX_U32 ii;
1350     OMX_BOOL FoundBuffer;
1351 
1352     if (nPortIndex >= iNumPorts)
1353     {
1354         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FreeBuffer error bad port index"));
1355         return OMX_ErrorBadPortIndex;
1356     }
1357 
1358     pBaseComponentPort = ipPorts[nPortIndex];
1359 
1360     if (pBaseComponentPort->TransientState != OMX_StateLoaded
1361             && pBaseComponentPort->TransientState != OMX_StateInvalid)
1362     {
1363 
1364         (*(ipCallbacks->EventHandler))
1365         (hComponent,
1366          iCallbackData,
1367          OMX_EventError, /* The command was completed */
1368          OMX_ErrorPortUnpopulated, /* The commands was a OMX_CommandStateSet */
1369          nPortIndex, /* The State has been changed in message->MessageParam2 */
1370          NULL);
1371     }
1372 
1373     for (ii = 0; ii < pBaseComponentPort->PortParam.nBufferCountActual; ii++)
1374     {
1375         if ((pBaseComponentPort->BufferState[ii] & BUFFER_ALLOCATED) &&
1376                 (pBaseComponentPort->pBuffer[ii]->pBuffer == pBuffer->pBuffer))
1377         {
1378 
1379             pBaseComponentPort->NumAssignedBuffers--;
1380             oscl_free(pBuffer->pBuffer);
1381             pBuffer->pBuffer = NULL;
1382 
1383             if (pBaseComponentPort->BufferState[ii] & HEADER_ALLOCATED)
1384             {
1385                 oscl_free(pBuffer);
1386                 pBuffer = NULL;
1387             }
1388             pBaseComponentPort->BufferState[ii] = BUFFER_FREE;
1389             break;
1390         }
1391         else if ((pBaseComponentPort->BufferState[ii] & BUFFER_ASSIGNED) &&
1392                  (pBaseComponentPort->pBuffer[ii] == pBuffer))
1393         {
1394 
1395             pBaseComponentPort->NumAssignedBuffers--;
1396 
1397             if (pBaseComponentPort->BufferState[ii] & HEADER_ALLOCATED)
1398             {
1399                 oscl_free(pBuffer);
1400                 pBuffer = NULL;
1401             }
1402 
1403             pBaseComponentPort->BufferState[ii] = BUFFER_FREE;
1404             break;
1405         }
1406     }
1407 
1408     FoundBuffer = OMX_FALSE;
1409 
1410     for (ii = 0; ii < pBaseComponentPort->PortParam.nBufferCountActual; ii++)
1411     {
1412         if (pBaseComponentPort->BufferState[ii] != BUFFER_FREE)
1413         {
1414             FoundBuffer = OMX_TRUE;
1415             break;
1416         }
1417     }
1418     if (!FoundBuffer)
1419     {
1420         pBaseComponentPort->PortParam.bPopulated = OMX_FALSE;
1421 
1422         if (OMX_TRUE == iStateTransitionFlag)
1423         {
1424             //Reschedule the AO for a state change (Idle->Loaded) if its pending on buffer de-allocation
1425             RunIfNotReady();
1426             iStateTransitionFlag = OMX_FALSE;
1427 
1428             //Reset the decoding flags while freeing buffers
1429             if (OMX_PORT_INPUTPORT_INDEX == nPortIndex)
1430             {
1431                 iIsInputBufferEnded = OMX_TRUE;
1432                 iTempInputBufferLength = 0;
1433                 iTempConsumedLength = 0;
1434                 iNewInBufferRequired = OMX_TRUE;
1435             }
1436             else if (OMX_PORT_OUTPUTPORT_INDEX == nPortIndex)
1437             {
1438                 iNewOutBufRequired = OMX_TRUE;
1439             }
1440         }
1441 
1442         if (NULL != pBaseComponentPort->pBuffer)
1443         {
1444             oscl_free(pBaseComponentPort->pBuffer);
1445             pBaseComponentPort->pBuffer = NULL;
1446             oscl_free(pBaseComponentPort->BufferState);
1447             pBaseComponentPort->BufferState = NULL;
1448         }
1449     }
1450 
1451     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FreeBuffer OUT"));
1452     return OMX_ErrorNone;
1453 }
1454 
1455 
1456 /** Set Callbacks. It stores in the component private structure the pointers to the user application callbacs
1457     * @param hComponent the handle of the component
1458     * @param ipCallbacks the OpenMAX standard structure that holds the callback pointers
1459     * @param pAppData a pointer to a private structure, not covered by OpenMAX standard, in needed
1460     */
1461 
BaseComponentSetCallbacks(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_CALLBACKTYPE * pCallbacks,OMX_IN OMX_PTR pAppData)1462 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentSetCallbacks(
1463     OMX_IN  OMX_HANDLETYPE hComponent,
1464     OMX_IN  OMX_CALLBACKTYPE* pCallbacks,
1465     OMX_IN  OMX_PTR pAppData)
1466 {
1467     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
1468     OMX_ERRORTYPE Status;
1469 
1470     if (NULL == pOpenmaxAOType)
1471     {
1472         return OMX_ErrorBadParameter;
1473     }
1474 
1475     Status = pOpenmaxAOType->SetCallbacks(hComponent, pCallbacks, pAppData);
1476 
1477     return Status;
1478 }
1479 
1480 
SetCallbacks(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_CALLBACKTYPE * pCallbacks,OMX_IN OMX_PTR pAppData)1481 OMX_ERRORTYPE OmxComponentBase::SetCallbacks(
1482     OMX_IN  OMX_HANDLETYPE hComponent,
1483     OMX_IN  OMX_CALLBACKTYPE* pCallbacks,
1484     OMX_IN  OMX_PTR pAppData)
1485 {
1486     OSCL_UNUSED_ARG(hComponent);
1487 
1488     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SetCallbacks"));
1489     ipCallbacks = pCallbacks;
1490     iCallbackData = pAppData;
1491 
1492     return OMX_ErrorNone;
1493 }
1494 
1495 
BaseComponentSendCommand(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_COMMANDTYPE Cmd,OMX_IN OMX_U32 nParam,OMX_IN OMX_PTR pCmdData)1496 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentSendCommand(
1497     OMX_IN  OMX_HANDLETYPE hComponent,
1498     OMX_IN  OMX_COMMANDTYPE Cmd,
1499     OMX_IN  OMX_U32 nParam,
1500     OMX_IN  OMX_PTR pCmdData)
1501 {
1502 
1503     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
1504     OMX_ERRORTYPE Status;
1505 
1506     if (NULL == pOpenmaxAOType)
1507     {
1508         return OMX_ErrorBadParameter;
1509     }
1510 
1511     Status = pOpenmaxAOType->SendCommand(hComponent, Cmd, nParam, pCmdData);
1512 
1513     return Status;
1514 }
1515 
SendCommand(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_COMMANDTYPE Cmd,OMX_IN OMX_S32 nParam,OMX_IN OMX_PTR pCmdData)1516 OMX_ERRORTYPE OmxComponentBase::SendCommand(
1517     OMX_IN  OMX_HANDLETYPE hComponent,
1518     OMX_IN  OMX_COMMANDTYPE Cmd,
1519     OMX_IN  OMX_S32 nParam,
1520     OMX_IN  OMX_PTR pCmdData)
1521 {
1522 
1523     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand IN"));
1524 
1525     OMX_U32 ii;
1526     OMX_ERRORTYPE ErrMsgHandler = OMX_ErrorNone;
1527     QueueType* pMessageQueue;
1528     CoreMessage* Message = NULL;
1529     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
1530 
1531     pMessageQueue = ipCoreDescriptor->pMessageQueue;
1532 
1533     if (OMX_StateInvalid == iState)
1534     {
1535         ErrMsgHandler = OMX_ErrorInvalidState;
1536     }
1537 
1538     switch (Cmd)
1539     {
1540         case OMX_CommandStateSet:
1541         {
1542             Message = (CoreMessage*) oscl_malloc(sizeof(CoreMessage));
1543 
1544             if (NULL == Message)
1545             {
1546                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error insufficient resources"));
1547                 return OMX_ErrorInsufficientResources;
1548             }
1549 
1550             Message->pComponent = (OMX_COMPONENTTYPE *) hComponent;
1551             Message->MessageType = SENDCOMMAND_MSG_TYPE;
1552             Message->MessageParam1 = OMX_CommandStateSet;
1553             Message->MessageParam2 = nParam;
1554             Message->pCmdData = pCmdData;
1555 
1556             if ((OMX_StateIdle == nParam) && (OMX_StateLoaded == iState))
1557             {
1558                 ErrMsgHandler = pOpenmaxAOType->ComponentInit();
1559 
1560                 if (OMX_ErrorNone != ErrMsgHandler)
1561                 {
1562                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error component init"));
1563                     return OMX_ErrorInsufficientResources;
1564                 }
1565                 for (ii = 0; ii < iNumPorts; ii++)
1566                 {
1567                     ipPorts[ii]->TransientState = OMX_StateIdle;
1568                 }
1569             }
1570             else if ((OMX_StateLoaded == nParam) && (OMX_StateIdle == iState))
1571             {
1572                 for (ii = 0; ii < iNumPorts; ii++)
1573                 {
1574                     if (PORT_IS_ENABLED(ipPorts[ii]))
1575                     {
1576                         ipPorts[ii]->TransientState = OMX_StateLoaded;
1577                     }
1578                 }
1579             }
1580             else if (OMX_StateInvalid == nParam)
1581             {
1582                 for (ii = 0; ii < iNumPorts; ii++)
1583                 {
1584                     if (PORT_IS_ENABLED(ipPorts[ii]))
1585                     {
1586                         ipPorts[ii]->TransientState = OMX_StateInvalid;
1587                     }
1588                 }
1589             }
1590             else if (((OMX_StateIdle == nParam) || (OMX_StatePause == nParam))
1591                      && (OMX_StateExecuting == iState))
1592             {
1593                 iBufferExecuteFlag = OMX_FALSE;
1594             }
1595 
1596         }
1597         break;
1598 
1599         case OMX_CommandFlush:
1600         {
1601             Message = (CoreMessage*) oscl_malloc(sizeof(CoreMessage));
1602 
1603             if (NULL == Message)
1604             {
1605                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error insufficient resources"));
1606                 return OMX_ErrorInsufficientResources;
1607             }
1608 
1609             Message->pComponent = (OMX_COMPONENTTYPE *) hComponent;
1610             Message->MessageType = SENDCOMMAND_MSG_TYPE;
1611             Message->MessageParam1 = OMX_CommandFlush;
1612             Message->MessageParam2 = nParam;
1613             Message->pCmdData = pCmdData;
1614 
1615             if ((iState != OMX_StateExecuting) && (iState != OMX_StatePause))
1616             {
1617                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error incorrect state"));
1618                 ErrMsgHandler = OMX_ErrorIncorrectStateOperation;
1619                 break;
1620 
1621             }
1622             if ((nParam != -1) && ((OMX_U32) nParam >= iNumPorts))
1623             {
1624                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error bad port index"));
1625                 return OMX_ErrorBadPortIndex;
1626             }
1627             SetPortFlushFlag(iNumPorts, nParam, OMX_TRUE);
1628             SetNumBufferFlush(iNumPorts, -1, 0);
1629         }
1630         break;
1631 
1632         case OMX_CommandPortDisable:
1633         {
1634             if ((nParam != -1) && ((OMX_U32) nParam >= iNumPorts))
1635             {
1636                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error bad port index"));
1637                 return OMX_ErrorBadPortIndex;
1638             }
1639 
1640             iResizePending = OMX_FALSE; // reset the flag to enable processing
1641             iSendOutBufferAfterPortReconfigFlag = OMX_TRUE;
1642 
1643 
1644             if (-1 == nParam)
1645             {
1646                 for (ii = 0; ii < iNumPorts; ii++)
1647                 {
1648                     if (!PORT_IS_ENABLED(ipPorts[ii]))
1649                     {
1650                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error incorrect state"));
1651                         ErrMsgHandler = OMX_ErrorIncorrectStateOperation;
1652                         break;
1653                     }
1654                     else
1655                     {
1656                         ipPorts[ii]->TransientState = OMX_StateLoaded;
1657                     }
1658                 }
1659             }
1660             else
1661             {
1662                 if (!PORT_IS_ENABLED(ipPorts[nParam]))
1663                 {
1664                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error incorrect state"));
1665                     ErrMsgHandler = OMX_ErrorIncorrectStateOperation;
1666                     break;
1667                 }
1668                 else
1669                 {
1670                     ipPorts[nParam]->TransientState = OMX_StateLoaded;
1671                 }
1672             }
1673 
1674             Message = (CoreMessage*) oscl_malloc(sizeof(CoreMessage));
1675             if (NULL == Message)
1676             {
1677                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error insufficient resources"));
1678                 return OMX_ErrorInsufficientResources;
1679             }
1680 
1681             Message->pComponent = (OMX_COMPONENTTYPE *) hComponent;
1682             if (OMX_ErrorNone == ErrMsgHandler)
1683             {
1684                 Message->MessageType = SENDCOMMAND_MSG_TYPE;
1685                 Message->MessageParam2 = nParam;
1686             }
1687             else
1688             {
1689                 Message->MessageType = ERROR_MSG_TYPE;
1690                 Message->MessageParam2 = ErrMsgHandler;
1691             }
1692             Message->MessageParam1 = OMX_CommandPortDisable;
1693             Message->pCmdData = pCmdData;
1694         }
1695         break;
1696 
1697 
1698         case OMX_CommandPortEnable:
1699         {
1700             if ((nParam != -1) && ((OMX_U32) nParam >= iNumPorts))
1701             {
1702                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error bad port index"));
1703                 return OMX_ErrorBadPortIndex;
1704             }
1705 
1706             if (-1 == nParam)
1707             {
1708                 for (ii = 0; ii < iNumPorts; ii++)
1709                 {
1710                     if (PORT_IS_ENABLED(ipPorts[ii]))
1711                     {
1712                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error incorrect state"));
1713                         ErrMsgHandler = OMX_ErrorIncorrectStateOperation;
1714                         break;
1715                     }
1716                     else
1717                     {
1718                         ipPorts[ii]->TransientState = OMX_StateIdle;
1719                     }
1720                 }
1721             }
1722             else
1723             {
1724                 if (PORT_IS_ENABLED(ipPorts[nParam]))
1725                 {
1726                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error incorrect state"));
1727                     ErrMsgHandler = OMX_ErrorIncorrectStateOperation;
1728                     break;
1729                 }
1730                 else
1731                 {
1732                     ipPorts[nParam]->TransientState = OMX_StateIdle;
1733                 }
1734             }
1735 
1736             Message = (CoreMessage*) oscl_malloc(sizeof(CoreMessage));
1737             if (NULL == Message)
1738             {
1739                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error insufficient resources"));
1740                 return OMX_ErrorInsufficientResources;
1741             }
1742 
1743             Message->pComponent = (OMX_COMPONENTTYPE *) hComponent;
1744             if (OMX_ErrorNone == ErrMsgHandler)
1745             {
1746                 Message->MessageType = SENDCOMMAND_MSG_TYPE;
1747             }
1748             else
1749             {
1750                 Message->MessageType = ERROR_MSG_TYPE;
1751             }
1752 
1753             Message->MessageParam1 = OMX_CommandPortEnable;
1754             Message->MessageParam2 = nParam;
1755             Message->pCmdData = pCmdData;
1756         }
1757         break;
1758 
1759 
1760         case OMX_CommandMarkBuffer:
1761         {
1762             if ((iState != OMX_StateExecuting) && (iState != OMX_StatePause))
1763             {
1764                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error incorrect state"));
1765                 ErrMsgHandler = OMX_ErrorIncorrectStateOperation;
1766                 break;
1767             }
1768 
1769             if ((nParam != -1) && ((OMX_U32) nParam >= iNumPorts))
1770             {
1771                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error bad port index"));
1772                 return OMX_ErrorBadPortIndex;
1773             }
1774 
1775             Message = (CoreMessage*) oscl_malloc(sizeof(CoreMessage));
1776             if (NULL == Message)
1777             {
1778                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error insufficient resources"));
1779                 return OMX_ErrorInsufficientResources;
1780             }
1781             Message->pComponent = (OMX_COMPONENTTYPE *) hComponent;
1782             Message->MessageType = SENDCOMMAND_MSG_TYPE;
1783             Message->MessageParam1 = OMX_CommandMarkBuffer;
1784             Message->MessageParam2 = nParam;
1785             Message->pCmdData = pCmdData;
1786         }
1787         break;
1788 
1789 
1790         default:
1791         {
1792             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error unsupported index"));
1793             ErrMsgHandler = OMX_ErrorUnsupportedIndex;
1794         }
1795         break;
1796     }
1797 
1798     if (OMX_ErrorNone != Queue(pMessageQueue, Message))
1799     {
1800         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand error, Queuing command failed"));
1801         return OMX_ErrorInsufficientResources;
1802     }
1803 
1804     RunIfNotReady();
1805 
1806     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : SendCommand OUT"));
1807     return ErrMsgHandler;
1808 }
1809 
1810 
1811 
1812 /* This routine will reset all the buffers and flag associated with decoding
1813  * when receiving a flush command on the respective port*/
ResetAfterFlush(OMX_S32 PortIndex)1814 void OmxComponentBase::ResetAfterFlush(OMX_S32 PortIndex)
1815 {
1816 
1817     if (OMX_PORT_INPUTPORT_INDEX == PortIndex || OMX_PORT_ALLPORT_INDEX == PortIndex)
1818     {
1819         iIsInputBufferEnded = OMX_TRUE;
1820         iEndofStream = OMX_FALSE;
1821         iNewInBufferRequired = OMX_TRUE;
1822         iPartialFrameAssembly = OMX_FALSE;
1823         iTempInputBufferLength = 0;
1824         iTempConsumedLength = 0;
1825         iInputBufferRemainingBytes = 0;
1826         iInputCurrLength = 0;
1827 
1828         //Assume for this state transition that reposition command has come
1829         iRepositionFlag = OMX_TRUE;
1830         //Reset the silence insertion logic also
1831         iSilenceInsertionInProgress = OMX_FALSE;
1832     }
1833 
1834     if (OMX_PORT_OUTPUTPORT_INDEX == PortIndex || OMX_PORT_ALLPORT_INDEX == PortIndex)
1835     {
1836         iNewOutBufRequired = OMX_TRUE;
1837     }
1838 
1839     return;
1840 }
1841 
1842 
1843 /** This is called by the OMX core in its message processing
1844  * thread context upon a component request. A request is made
1845  * by the component when some asynchronous services are needed:
1846  * 1) A SendCommand() is to be processed
1847  * 2) An error needs to be notified
1848  * \param Message, the message that has been passed to core
1849  */
1850 
MessageHandler(CoreMessage * Message)1851 OMX_ERRORTYPE OmxComponentBase::MessageHandler(CoreMessage* Message)
1852 {
1853 
1854     OMX_COMPONENTTYPE* pHandle = &iOmxComponent;
1855     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*) iOmxComponent.pComponentPrivate;
1856     OMX_U32 ii;
1857     OMX_ERRORTYPE ErrorType = OMX_ErrorNone;
1858 
1859 
1860     /** Dealing with a SendCommand call.
1861      * -MessageParam1 contains the command to execute
1862      * -MessageParam2 contains the parameter of the command
1863      *  (destination state in case of a state change command).
1864      */
1865 
1866     OMX_STATETYPE orig_state = iState;
1867     if (SENDCOMMAND_MSG_TYPE == Message->MessageType)
1868     {
1869         switch (Message->MessageParam1)
1870         {
1871             case OMX_CommandStateSet:
1872             {
1873                 /* Do the actual state change */
1874                 ErrorType = DoStateSet(Message->MessageParam2);
1875 
1876                 if (OMX_TRUE == iStateTransitionFlag)
1877                 {
1878                     return OMX_ErrorNone;
1879                 }
1880 
1881                 //Do not send the callback now till the State gets changed
1882                 if (ErrorType != OMX_ErrorNone)
1883                 {
1884                     (*(ipCallbacks->EventHandler))
1885                     (pHandle,
1886                      iCallbackData,
1887                      OMX_EventError, /* The command was completed */
1888                      ErrorType, /* The commands was a OMX_CommandStateSet */
1889                      0, /* The iState has been changed in Message->MessageParam2 */
1890                      NULL);
1891                 }
1892                 else
1893                 {
1894                     /* And run the callback */
1895                     (*(ipCallbacks->EventHandler))
1896                     (pHandle,
1897                      iCallbackData,
1898                      OMX_EventCmdComplete, /* The command was completed */
1899                      OMX_CommandStateSet, /* The commands was a OMX_CommandStateSet */
1900                      Message->MessageParam2, /* The iState has been changed in Message->MessageParam2 */
1901                      NULL);
1902                 }
1903             }
1904             break;
1905 
1906             case OMX_CommandFlush:
1907             {
1908                 /*Flush ports*/
1909                 ErrorType = FlushPort(Message->MessageParam2);
1910 
1911                 SetNumBufferFlush(iNumPorts, -1, 0);
1912 
1913                 ResetAfterFlush(Message->MessageParam2);
1914 
1915                 //If Flush Command has come at the input port, reset the individual component as well
1916                 if (OMX_PORT_INPUTPORT_INDEX == Message->MessageParam2
1917                         || OMX_PORT_ALLPORT_INDEX == Message->MessageParam2)
1918                 {
1919                     /* Component specific flush routine for input buffer where individual components
1920                      * may set/reset some flags/buffer lengths if required.*/
1921 
1922                     pOpenmaxAOType->ResetComponent();
1923                 }
1924 
1925                 if (ErrorType != OMX_ErrorNone)
1926                 {
1927                     (*(ipCallbacks->EventHandler))
1928                     (pHandle,
1929                      iCallbackData,
1930                      OMX_EventError, /* The command was completed */
1931                      ErrorType, /* The commands was a OMX_CommandStateSet */
1932                      0, /* The iState has been changed in Message->MessageParam2 */
1933                      NULL);
1934                 }
1935                 else
1936                 {
1937                     if (-1 == Message->MessageParam2)
1938                     {
1939                         /*Flush all port*/
1940                         for (ii = 0; ii < iNumPorts; ii++)
1941                         {
1942                             (*(ipCallbacks->EventHandler))
1943                             (pHandle,
1944                              iCallbackData,
1945                              OMX_EventCmdComplete, /* The command was completed */
1946                              OMX_CommandFlush, /* The commands was a OMX_CommandStateSet */
1947                              ii, /* The iState has been changed in Message->MessageParam2 */
1948                              NULL);
1949                         }
1950                     }
1951                     else
1952                     {
1953                         /*Flush input/output port*/
1954                         (*(ipCallbacks->EventHandler))
1955                         (pHandle,
1956                          iCallbackData,
1957                          OMX_EventCmdComplete, /* The command was completed */
1958                          OMX_CommandFlush, /* The commands was a OMX_CommandStateSet */
1959                          Message->MessageParam2, /* The iState has been changed in Message->MessageParam2 */
1960                          NULL);
1961                     }
1962                 }
1963                 SetPortFlushFlag(iNumPorts, -1, OMX_FALSE);
1964             }
1965             break;
1966 
1967             case OMX_CommandPortDisable:
1968             {
1969                 /** This condition is added to pass the tests, it is not significant for the environment */
1970                 ErrorType = DisablePort(Message->MessageParam2);
1971                 if (OMX_TRUE == iStateTransitionFlag)
1972                 {
1973                     return OMX_ErrorNone;
1974                 }
1975 
1976                 if (ErrorType != OMX_ErrorNone)
1977                 {
1978                     (*(ipCallbacks->EventHandler))
1979                     (pHandle,
1980                      iCallbackData,
1981                      OMX_EventError, /* The command was completed */
1982                      ErrorType, /* The commands was a OMX_CommandStateSet */
1983                      0, /* The iState has been changed in Message->MessageParam2 */
1984                      NULL);
1985                 }
1986                 else
1987                 {
1988                     if (-1 == Message->MessageParam2)
1989                     {
1990                         /*Disable all ports*/
1991                         for (ii = 0; ii < iNumPorts; ii++)
1992                         {
1993                             (*(ipCallbacks->EventHandler))
1994                             (pHandle,
1995                              iCallbackData,
1996                              OMX_EventCmdComplete, /* The command was completed */
1997                              OMX_CommandPortDisable, /* The commands was a OMX_CommandStateSet */
1998                              ii, /* The iState has been changed in Message->MessageParam2 */
1999                              NULL);
2000                         }
2001                     }
2002                     else
2003                     {
2004                         (*(ipCallbacks->EventHandler))
2005                         (pHandle,
2006                          iCallbackData,
2007                          OMX_EventCmdComplete, /* The command was completed */
2008                          OMX_CommandPortDisable, /* The commands was a OMX_CommandStateSet */
2009                          Message->MessageParam2, /* The iState has been changed in Message->MessageParam2 */
2010                          NULL);
2011                     }
2012                 }
2013             }
2014             break;
2015 
2016             case OMX_CommandPortEnable:
2017             {
2018                 ErrorType = EnablePort(Message->MessageParam2);
2019                 if (OMX_TRUE == iStateTransitionFlag)
2020                 {
2021                     return OMX_ErrorNone;
2022                 }
2023 
2024                 if (ErrorType != OMX_ErrorNone)
2025                 {
2026                     (*(ipCallbacks->EventHandler))
2027                     (pHandle,
2028                      iCallbackData,
2029                      OMX_EventError, /* The command was completed */
2030                      ErrorType, /* The commands was a OMX_CommandStateSet */
2031                      0, /* The State has been changed in Message->MessageParam2 */
2032                      NULL);
2033                 }
2034                 else
2035                 {
2036                     if (Message->MessageParam2 != -1)
2037                     {
2038                         (*(ipCallbacks->EventHandler))
2039                         (pHandle,
2040                          iCallbackData,
2041                          OMX_EventCmdComplete, /* The command was completed */
2042                          OMX_CommandPortEnable, /* The commands was a OMX_CommandStateSet */
2043                          Message->MessageParam2, /* The State has been changed in Message->MessageParam2 */
2044                          NULL);
2045                     }
2046                     else
2047                     {
2048                         for (ii = 0; ii < iNumPorts; ii++)
2049                         {
2050                             (*(ipCallbacks->EventHandler))
2051                             (pHandle,
2052                              iCallbackData,
2053                              OMX_EventCmdComplete, /* The command was completed */
2054                              OMX_CommandPortEnable, /* The commands was a OMX_CommandStateSet */
2055                              ii, /* The State has been changed in Message->MessageParam2 */
2056                              NULL);
2057                         }
2058                     }
2059                 }
2060             }
2061             break;
2062 
2063             case OMX_CommandMarkBuffer:
2064             {
2065                 ipMark = (OMX_MARKTYPE *)Message->pCmdData;
2066             }
2067             break;
2068 
2069             default:
2070             {
2071 
2072             }
2073             break;
2074         }
2075         /* Dealing with an asynchronous error condition
2076          */
2077     }
2078 
2079     if (orig_state != OMX_StateInvalid)
2080     {
2081         ErrorType = OMX_ErrorNone;
2082     }
2083 
2084     return ErrorType;
2085 }
2086 
2087 /** Changes the state of a component taking proper actions depending on
2088  * the transiotion requested
2089  * \param aDestinationState the requested target state.
2090  */
2091 
DoStateSet(OMX_U32 aDestinationState)2092 OMX_ERRORTYPE OmxComponentBase::DoStateSet(OMX_U32 aDestinationState)
2093 {
2094     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE,
2095                     (0, "OmxComponentBase : DoStateSet IN : iState (%i) aDestinationState (%i)", iState, aDestinationState));
2096 
2097     OMX_ERRORTYPE ErrorType = OMX_ErrorNone;
2098     OMX_U32 ii;
2099 
2100     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*) iOmxComponent.pComponentPrivate;
2101 
2102     if (OMX_StateLoaded == aDestinationState)
2103     {
2104         switch (iState)
2105         {
2106             case OMX_StateInvalid:
2107             {
2108                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error invalid state"));
2109                 return OMX_ErrorInvalidState;
2110             }
2111 
2112             case OMX_StateWaitForResources:
2113             {
2114                 iState = OMX_StateLoaded;
2115             }
2116             break;
2117 
2118             case OMX_StateLoaded:
2119             {
2120                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error same state"));
2121                 return OMX_ErrorSameState;
2122             }
2123 
2124             case OMX_StateIdle:
2125             {
2126                 for (ii = 0; ii < iNumPorts; ii++)
2127                 {
2128                     if (PORT_IS_ENABLED(ipPorts[ii]) && PORT_IS_POPULATED(ipPorts[ii]))
2129                     {
2130                         iStateTransitionFlag = OMX_TRUE;
2131                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet Waiting port to be de-populated"));
2132                         return OMX_ErrorNone;
2133                     }
2134                 }
2135 
2136                 iState = OMX_StateLoaded;
2137 
2138                 iNumInputBuffer = 0;
2139                 iOutBufferCount = 0;
2140                 iPartialFrameAssembly = OMX_FALSE;
2141                 iEndofStream = OMX_FALSE;
2142                 iIsInputBufferEnded = OMX_TRUE;
2143                 iNewOutBufRequired = OMX_TRUE;
2144                 iNewInBufferRequired = OMX_TRUE;
2145                 iFirstFragment = OMX_FALSE;
2146 
2147                 pOpenmaxAOType->ComponentDeInit();
2148             }
2149             break;
2150 
2151             default:
2152             {
2153                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error incorrect state"));
2154                 return OMX_ErrorIncorrectStateTransition;
2155             }
2156         }
2157         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet OUT"));
2158         return OMX_ErrorNone;
2159     }
2160 
2161     if (OMX_StateWaitForResources == aDestinationState)
2162     {
2163         switch (iState)
2164         {
2165             case OMX_StateInvalid:
2166             {
2167                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error invalid state"));
2168                 return OMX_ErrorInvalidState;
2169             }
2170 
2171             case OMX_StateLoaded:
2172             {
2173                 iState = OMX_StateWaitForResources;
2174             }
2175             break;
2176 
2177             case OMX_StateWaitForResources:
2178             {
2179                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error same state"));
2180                 return OMX_ErrorSameState;
2181             }
2182 
2183             default:
2184             {
2185                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error incorrect state"));
2186                 return OMX_ErrorIncorrectStateTransition;
2187             }
2188         }
2189         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet OUT"));
2190         return OMX_ErrorNone;
2191     }
2192 
2193     if (OMX_StateIdle == aDestinationState)
2194     {
2195         switch (iState)
2196         {
2197             case OMX_StateInvalid:
2198             {
2199                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error invalid state"));
2200                 return OMX_ErrorInvalidState;
2201             }
2202 
2203             case OMX_StateWaitForResources:
2204             {
2205                 iState = OMX_StateIdle;
2206             }
2207             break;
2208 
2209             case OMX_StateLoaded:
2210             {
2211                 for (ii = 0; ii < iNumPorts; ii++)
2212                 {
2213                     if (PORT_IS_ENABLED(ipPorts[ii]) && !PORT_IS_POPULATED(ipPorts[ii]))
2214                     {
2215                         iStateTransitionFlag = OMX_TRUE;
2216                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet Waiting port to be populated"));
2217                         return OMX_ErrorNone;
2218                     }
2219                 }
2220 
2221                 iState = OMX_StateIdle;
2222 
2223                 //Used in case of partial frame assembly
2224                 if (!ipInputCurrBuffer)
2225                 {
2226                     //Keep the size of temp buffer double to be on safer side
2227                     iInputCurrBufferSize = 2 * sizeof(uint8) * (ipPorts[OMX_PORT_INPUTPORT_INDEX]->PortParam.nBufferSize);
2228 
2229                     ipInputCurrBuffer = (OMX_U8*) oscl_malloc(iInputCurrBufferSize);
2230                     if (NULL == ipInputCurrBuffer)
2231                     {
2232                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error insufficient resources"));
2233                         return OMX_ErrorInsufficientResources;
2234                     }
2235 
2236                 }
2237 
2238                 //Used when the buffers are not marked with EndOfFrame flag
2239                 if (!ipTempInputBuffer)
2240                 {
2241                     ipTempInputBuffer = (OMX_U8*) oscl_malloc(iInputCurrBufferSize);
2242                     if (NULL == ipTempInputBuffer)
2243                     {
2244                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error insufficient resources"));
2245                         return OMX_ErrorInsufficientResources;
2246                     }
2247                 }
2248 
2249                 iTempInputBufferLength = 0;
2250                 iTempConsumedLength = 0;
2251                 iInputBufferRemainingBytes = 0;
2252             }
2253             break;
2254 
2255             case OMX_StateIdle:
2256             {
2257                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error same state"));
2258                 return OMX_ErrorSameState;
2259             }
2260 
2261             //Both the below cases have same body
2262             case OMX_StateExecuting:
2263             case OMX_StatePause:
2264             {
2265                 SetNumBufferFlush(iNumPorts, -1, 0);
2266                 SetPortFlushFlag(iNumPorts, -1, OMX_TRUE);
2267 
2268                 ComponentPortType* pInPort = (ComponentPortType*) ipPorts[OMX_PORT_INPUTPORT_INDEX];
2269 
2270                 //Return all the buffers if still occupied
2271                 QueueType* pInputQueue = ipPorts[OMX_PORT_INPUTPORT_INDEX]->pBufferQueue;
2272 
2273                 while ((iNumInputBuffer > 0) && (GetQueueNumElem(pInputQueue) > 0))
2274                 {
2275                     FlushPort(OMX_PORT_INPUTPORT_INDEX);
2276                 }
2277 
2278                 // if a buffer was previously dequeued, it wasnt freed in above loop. return it now
2279                 if (iNumInputBuffer > 0)
2280                 {
2281                     ipInputBuffer->nFilledLen = 0;
2282                     ReturnInputBuffer(ipInputBuffer, pInPort);
2283                     iNewInBufferRequired = OMX_TRUE;
2284                     iIsInputBufferEnded = OMX_TRUE;
2285                     iInputCurrLength = 0;
2286                     ipInputBuffer = NULL;
2287                 }
2288 
2289                 //Return all the buffers if still occupied
2290                 while ((iNumInputBuffer > 0))
2291                 {
2292                     FlushPort(OMX_PORT_INPUTPORT_INDEX);
2293                 }
2294 
2295                 //Return all the output buffers if still occupied
2296                 while (iOutBufferCount > 0)
2297                 {
2298                     FlushPort(OMX_PORT_OUTPUTPORT_INDEX);
2299                 }
2300 
2301                 //Call the reset funstion here to reset the flags and buffer length variables
2302                 ResetAfterFlush(OMX_PORT_ALLPORT_INDEX);
2303 
2304 
2305                 SetPortFlushFlag(iNumPorts, -1, OMX_FALSE);
2306                 SetNumBufferFlush(iNumPorts, -1, 0);
2307 
2308                 pOpenmaxAOType->ResetComponent();
2309 
2310                 iState = OMX_StateIdle;
2311             }
2312             break;
2313 
2314             default:
2315             {
2316                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error incorrect state"));
2317                 return OMX_ErrorIncorrectStateTransition;
2318             }
2319         }
2320 
2321         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet OUT"));
2322         return ErrorType;
2323     }
2324 
2325     if (OMX_StatePause == aDestinationState)
2326     {
2327         switch (iState)
2328         {
2329             case OMX_StateInvalid:
2330             {
2331                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error invalid state"));
2332                 return OMX_ErrorInvalidState;
2333             }
2334 
2335             case OMX_StatePause:
2336             {
2337                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error same state"));
2338                 return OMX_ErrorSameState;
2339             }
2340 
2341             //Falling through to the next case
2342             case OMX_StateExecuting:
2343             case OMX_StateIdle:
2344             {
2345                 iState = OMX_StatePause;
2346             }
2347             break;
2348 
2349             default:
2350             {
2351                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error incorrect state"));
2352                 return OMX_ErrorIncorrectStateTransition;
2353             }
2354         }
2355 
2356         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet OUT"));
2357         return OMX_ErrorNone;
2358     }
2359 
2360     if (OMX_StateExecuting == aDestinationState)
2361     {
2362         switch (iState)
2363         {
2364             case OMX_StateInvalid:
2365             {
2366                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error invalid state"));
2367                 return OMX_ErrorInvalidState;
2368             }
2369 
2370             case OMX_StateIdle:
2371             {
2372                 iState = OMX_StateExecuting;
2373             }
2374             break;
2375 
2376             case OMX_StatePause:
2377             {
2378                 iState = OMX_StateExecuting;
2379                 /* A trigger to start the processing of buffers when component
2380                  * transitions to executing from pause, as it is already
2381                  * holding the required buffers
2382                  */
2383                 RunIfNotReady();
2384             }
2385             break;
2386 
2387             case OMX_StateExecuting:
2388             {
2389                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error same state"));
2390                 return OMX_ErrorSameState;
2391             }
2392 
2393             default:
2394             {
2395                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error incorrect state"));
2396                 return OMX_ErrorIncorrectStateTransition;
2397             }
2398         }
2399 
2400         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet OUT"));
2401         return OMX_ErrorNone;
2402     }
2403 
2404     if (OMX_StateInvalid == aDestinationState)
2405     {
2406         switch (iState)
2407         {
2408             case OMX_StateInvalid:
2409             {
2410                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error invalid state"));
2411                 return OMX_ErrorInvalidState;
2412             }
2413 
2414             default:
2415             {
2416                 iState = OMX_StateInvalid;
2417                 if (iIsInit != OMX_FALSE)
2418                 {
2419                     pOpenmaxAOType->ComponentDeInit();
2420                 }
2421             }
2422             break;
2423         }
2424 
2425         if (iIsInit != OMX_FALSE)
2426         {
2427             pOpenmaxAOType->ComponentDeInit();
2428         }
2429 
2430         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet error invalid state"));
2431         return OMX_ErrorInvalidState;
2432     }
2433 
2434     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : DoStateSet OUT"));
2435     return OMX_ErrorNone;
2436 }
2437 
2438 
2439 
BaseComponentEmptyThisBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)2440 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentEmptyThisBuffer(
2441     OMX_IN  OMX_HANDLETYPE hComponent,
2442     OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
2443 {
2444 
2445     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate;
2446     OMX_ERRORTYPE Status;
2447 
2448     if (NULL == pOpenmaxAOType)
2449     {
2450         return OMX_ErrorBadParameter;
2451     }
2452 
2453     Status = pOpenmaxAOType->EmptyThisBuffer(hComponent, pBuffer);
2454 
2455     return Status;
2456 
2457 }
2458 
2459 
EmptyThisBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)2460 OMX_ERRORTYPE OmxComponentBase::EmptyThisBuffer(
2461     OMX_IN  OMX_HANDLETYPE hComponent,
2462     OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
2463 
2464 {
2465     OSCL_UNUSED_ARG(hComponent);
2466     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : EmptyThisBuffer IN"));
2467     //Do not queue buffers if component is in invalid state
2468     if (OMX_StateInvalid == iState)
2469     {
2470         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : EmptyThisBuffer error invalid state"));
2471         return OMX_ErrorInvalidState;
2472     }
2473 
2474     if ((OMX_StateIdle == iState) || (OMX_StatePause == iState) || (OMX_StateExecuting == iState))
2475     {
2476         OMX_U32 PortIndex;
2477         QueueType* pInputQueue;
2478         OMX_ERRORTYPE ErrorType = OMX_ErrorNone;
2479 
2480         PortIndex = pBuffer->nInputPortIndex;
2481 
2482         //Validate the port index & Queue the buffers available only at the input port
2483         if (PortIndex >= iNumPorts ||
2484                 ipPorts[PortIndex]->PortParam.eDir != OMX_DirInput)
2485         {
2486             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : EmptyThisBuffer error bad port index"));
2487             return OMX_ErrorBadPortIndex;
2488         }
2489 
2490         //Port should be in enabled state before accepting buffers
2491         if (!PORT_IS_ENABLED(ipPorts[PortIndex]))
2492         {
2493             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : EmptyThisBuffer error incorrect state"));
2494             return OMX_ErrorIncorrectStateOperation;
2495         }
2496 
2497         /* The number of buffers the component can queue at a time
2498          * depends upon the number of buffers allocated/assigned on the input port
2499          */
2500         if (iNumInputBuffer == (ipPorts[PortIndex]->NumAssignedBuffers))
2501         {
2502             RunIfNotReady();
2503             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : EmptyThisBuffer error incorrect state"));
2504             return OMX_ErrorIncorrectStateOperation;
2505         }
2506 
2507         //Finally after passing all the conditions, queue the buffer in Input queue
2508         pInputQueue = ipPorts[PortIndex]->pBufferQueue;
2509 
2510         if ((ErrorType = CheckHeader(pBuffer, sizeof(OMX_BUFFERHEADERTYPE))) != OMX_ErrorNone)
2511         {
2512             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : EmptyThisBuffer error check header failed"));
2513             return ErrorType;
2514         }
2515 
2516         if (OMX_ErrorNone != Queue(pInputQueue, pBuffer))
2517         {
2518             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : EmptyThisBuffer error, Queuing buffer failed"));
2519             return OMX_ErrorInsufficientResources;
2520         }
2521         iNumInputBuffer++;
2522 
2523         //Signal the AO about the incoming buffer
2524         RunIfNotReady();
2525     }
2526     else
2527     {
2528         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : EmptyThisBuffer error incorrect state"));
2529         //This macro is not accepted in any other state except the three mentioned above
2530         return OMX_ErrorIncorrectStateOperation;
2531     }
2532 
2533     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : EmptyThisBuffer OUT"));
2534 
2535     return OMX_ErrorNone;
2536 }
2537 
2538 
BaseComponentFillThisBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)2539 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentFillThisBuffer(
2540     OMX_IN  OMX_HANDLETYPE hComponent,
2541     OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
2542 {
2543 
2544     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
2545     OMX_ERRORTYPE Status;
2546 
2547     if (NULL == pOpenmaxAOType)
2548     {
2549         return OMX_ErrorBadParameter;
2550     }
2551 
2552     Status = pOpenmaxAOType->FillThisBuffer(hComponent, pBuffer);
2553 
2554     return Status;
2555 }
2556 
FillThisBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)2557 OMX_ERRORTYPE OmxComponentBase::FillThisBuffer(
2558     OMX_IN  OMX_HANDLETYPE hComponent,
2559     OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
2560 
2561 {
2562     OSCL_UNUSED_ARG(hComponent);
2563     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FillThisBuffer IN"));
2564 
2565     OMX_U32 PortIndex;
2566 
2567     QueueType* pOutputQueue;
2568     OMX_ERRORTYPE ErrorType = OMX_ErrorNone;
2569 
2570     PortIndex = pBuffer->nOutputPortIndex;
2571     //Validate the port index & Queue the buffers available only at the output port
2572     if (PortIndex >= iNumPorts ||
2573             ipPorts[PortIndex]->PortParam.eDir != OMX_DirOutput)
2574     {
2575         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FillThisBuffer error bad port index"));
2576         return OMX_ErrorBadPortIndex;
2577     }
2578 
2579     pOutputQueue = ipPorts[PortIndex]->pBufferQueue;
2580     if (iState != OMX_StateExecuting &&
2581             iState != OMX_StatePause &&
2582             iState != OMX_StateIdle)
2583     {
2584         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FillThisBuffer error invalid state"));
2585         return OMX_ErrorInvalidState;
2586     }
2587 
2588     //Port should be in enabled state before accepting buffers
2589     if (!PORT_IS_ENABLED(ipPorts[PortIndex]))
2590     {
2591         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FillThisBuffer error incorrect state"));
2592         return OMX_ErrorIncorrectStateOperation;
2593     }
2594 
2595     if ((ErrorType = CheckHeader(pBuffer, sizeof(OMX_BUFFERHEADERTYPE))) != OMX_ErrorNone)
2596     {
2597         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FillThisBuffer error check header failed"));
2598         return ErrorType;
2599     }
2600 
2601     //Queue the buffer in output queue
2602     if (OMX_ErrorNone != Queue(pOutputQueue, pBuffer))
2603     {
2604         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FillThisBuffer error, queuing buffer failed"));
2605         return OMX_ErrorInsufficientResources;
2606     }
2607 
2608     iOutBufferCount++;
2609 
2610     //Signal the AO about the incoming buffer
2611     RunIfNotReady();
2612 
2613     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : FillThisBuffer OUT"));
2614 
2615     return OMX_ErrorNone;
2616 }
2617 
2618 
2619 /** This is the central function for buffers processing and decoding.
2620     * It is called through the Run() of active object when the component is in executing state
2621     * and is signalled each time a new buffer is available on the given ports
2622     * This function will process the input buffers & return output buffers
2623     */
2624 
BufferMgmtFunction()2625 OSCL_EXPORT_REF void OmxComponentBase::BufferMgmtFunction()
2626 {
2627     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtFunction IN"));
2628 
2629     OMX_COMPONENTTYPE* pHandle = &iOmxComponent;
2630     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*) iOmxComponent.pComponentPrivate;
2631 
2632     QueueType* pInputQueue = ipPorts[OMX_PORT_INPUTPORT_INDEX]->pBufferQueue;
2633     QueueType* pOutputQueue = ipPorts[OMX_PORT_OUTPUTPORT_INDEX]->pBufferQueue;
2634     ComponentPortType* pInPort = (ComponentPortType*) ipPorts[OMX_PORT_INPUTPORT_INDEX];
2635 
2636     OMX_BOOL PartialFrameReturn, Status;
2637 
2638     /* Don't dequeue any further buffer after endofstream buffer has been dequeued
2639      * till we send the callback and reset the flag back to false
2640      */
2641     if (OMX_FALSE == iEndofStream)
2642     {
2643         //More than one frame can't be dequeued in case of outbut blocked
2644         if ((OMX_TRUE == iIsInputBufferEnded) && (GetQueueNumElem(pInputQueue) > 0))
2645         {
2646             ipInputBuffer = (OMX_BUFFERHEADERTYPE*) DeQueue(pInputQueue);
2647             if (NULL == ipInputBuffer)
2648             {
2649                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtFunction ERROR DeQueue() returned NULL"));
2650                 return;
2651             }
2652 
2653             if (ipInputBuffer->nFlags & OMX_BUFFERFLAG_EOS)
2654             {
2655                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtFunction EndOfStream arrived"));
2656                 iEndofStream = OMX_TRUE;
2657             }
2658 
2659             // To do: test this second condition newly added
2660             if ((ipInputBuffer->nFilledLen != 0) ||
2661                     ((OMX_TRUE == iEndofStream) && (OMX_TRUE == iPartialFrameAssembly)))
2662             {
2663                 // if we already started assembling frames, it means
2664                 // we didn't get marker bit yet, but may be getting it
2665                 // when the first frame assembly is over
2666                 // If so, we'll set iEndOfFrameFlag to TRUE in BufferMgmtWithoutMarker assembly
2667                 if (0 == iFrameCount && iPartialFrameAssembly == OMX_FALSE)
2668                 {
2669                     //Set the marker flag (iEndOfFrameFlag) if first frame has the EndOfFrame flag marked.
2670                     if ((ipInputBuffer->nFlags & OMX_BUFFERFLAG_ENDOFFRAME) != 0)
2671                     {
2672                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtFunction EndOfFrame flag present"));
2673                         iEndOfFrameFlag = OMX_TRUE;
2674                     }
2675 
2676                     /* This routine will allocate the internal input buffers that are required to
2677                      * assemble partial frames in both with and without marker mode for H.263 decoder component.
2678                      * The size of partial frame assembly buffer will be in proportion to the W & H of the clip.
2679                      * We require maximum of first 12 bytes of data (this will be checked */
2680 
2681 
2682                     if (OMX_ErrorNone != pOpenmaxAOType->ReAllocatePartialAssemblyBuffers(ipInputBuffer))
2683                     {
2684                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtFunction Error Memory Re-allocation of partial frame assembly buffer failed, OUT"));
2685                         return;
2686                     }
2687 
2688                 }
2689 
2690                 /* This condition will be true if OMX_BUFFERFLAG_ENDOFFRAME flag is
2691                  *  not marked in all the input buffers
2692                  */
2693                 if (!iEndOfFrameFlag)
2694                 {
2695                     Status = pOpenmaxAOType->BufferMgmtWithoutMarker();
2696                     if (OMX_FALSE == Status)
2697                     {
2698                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtFunction OUT"));
2699                         return;
2700                     }
2701 
2702                 }
2703                 //If OMX_BUFFERFLAG_ENDOFFRAME flag is marked, come here
2704                 else
2705                 {
2706                     if (iPVCapabilityFlags.iOMXComponentUsesFullAVCFrames && (OMX_PORT_INPUTPORT_INDEX == iCompressedFormatPortNum))
2707                     {
2708                         // since full frames are sent, there will never be partial frame assembly,
2709                         // but we do need to parse the frames into NALs to send to the decoder
2710                         PartialFrameReturn = ParseFullAVCFramesIntoNALs(ipInputBuffer);
2711                     }
2712                     else
2713                     {
2714                         PartialFrameReturn = AssemblePartialFrames(ipInputBuffer);
2715                     }
2716                     if (OMX_FALSE == PartialFrameReturn)
2717                     {
2718                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtFunction OUT"));
2719                         return;
2720                     }
2721                     iIsInputBufferEnded = OMX_FALSE;
2722 
2723                     ipTargetComponent = (OMX_COMPONENTTYPE*) ipInputBuffer->hMarkTargetComponent;
2724 
2725                     iTargetMarkData = ipInputBuffer->pMarkData;
2726                     if (ipTargetComponent == (OMX_COMPONENTTYPE*) pHandle)
2727                     {
2728                         (*(ipCallbacks->EventHandler))
2729                         (pHandle,
2730                          iCallbackData,
2731                          OMX_EventMark,
2732                          1,
2733                          0,
2734                          ipInputBuffer->pMarkData);
2735                     }
2736                 }
2737 
2738                 /* This routine will take care of any audio component specific tasks like
2739                    -> Reading the input buffer timestamp
2740                    -> Checking for Silence insertion
2741                    -> Repostioning implementation etc
2742                 */
2743                 if (OMX_TRUE == iIsAudioComponent)
2744                 {
2745                     pOpenmaxAOType->SyncWithInputTimestamp();
2746                 }
2747 
2748 
2749             }   //end braces for if (ipInputBuffer->nFilledLen != 0)
2750             else
2751             {
2752                 //Reschedule the AO if there are more buffers in queue
2753                 if ((GetQueueNumElem(pInputQueue) > 0) &&
2754                         ((GetQueueNumElem(pOutputQueue) > 0) || (OMX_FALSE == iNewOutBufRequired)))
2755                 {
2756                     RunIfNotReady();
2757                 }
2758 
2759                 ReturnInputBuffer(ipInputBuffer, pInPort);
2760                 ipInputBuffer = NULL;
2761             }
2762 
2763         }   //end braces for if ((OMX_TRUE == iIsInputBufferEnded) && (GetQueueNumElem(pInputQueue) > 0))
2764     }   //if (OMX_FALSE == iEndofStream)
2765 
2766 
2767     //Component specific Encode/Decode routine
2768     pOpenmaxAOType->ProcessData();
2769 
2770     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtFunction OUT"));
2771     return;
2772 }
2773 
2774 
BufferMgmtWithoutMarker()2775 OSCL_EXPORT_REF OMX_BOOL OmxComponentBase::BufferMgmtWithoutMarker()
2776 {
2777     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtWithoutMarker IN"));
2778 
2779     ComponentPortType*  pInPort = (ComponentPortType*) ipPorts[OMX_PORT_INPUTPORT_INDEX];
2780     QueueType* pInputQueue = ipPorts[OMX_PORT_INPUTPORT_INDEX]->pBufferQueue;
2781     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*) iOmxComponent.pComponentPrivate;
2782 
2783 
2784     /* If the buffer has enough data or EndofStream is true, and
2785      * partial frame assembly is not turned on, process the buffer independently */
2786 
2787     if (((ipInputBuffer->nFilledLen >= (iInputCurrBufferSize >> 1)) || (iEndofStream == OMX_TRUE))
2788             && (OMX_FALSE == iPartialFrameAssembly))
2789     {
2790         //This is a new piece of buffer, process it independently
2791         if (iNumInputBuffer > 0)
2792         {
2793             iInputCurrLength = ipInputBuffer->nFilledLen;
2794             ipFrameDecodeBuffer = ipInputBuffer->pBuffer + ipInputBuffer->nOffset;
2795             iFrameTimestamp = ipInputBuffer->nTimeStamp;
2796 
2797             /* Components not implementing ComponentBufferMgmtWithoutMarker(), will reset
2798              * iIsInputBufferEnded flag in the below routine */
2799             pOpenmaxAOType->ProcessInBufferFlag();
2800         }
2801         else
2802         {
2803             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtWithoutMarker OUT"));
2804             return OMX_FALSE; // nothing to decode
2805         }
2806     }
2807     else
2808     {
2809         if (!iPartialFrameAssembly)
2810         {
2811             iInputCurrLength = 0;
2812             ipFrameDecodeBuffer = ipInputCurrBuffer;
2813         }
2814 
2815         while (iNumInputBuffer > 0)
2816         {
2817             int32 BytesToCopy = ipInputBuffer->nFilledLen;
2818 
2819             if ((iInputCurrLength + BytesToCopy) > iInputCurrBufferSize)
2820             {
2821                 // allocate new partial frame buffers
2822                 OMX_U8* pTempNewBuffer = NULL;
2823                 pTempNewBuffer = (OMX_U8*) oscl_malloc(sizeof(OMX_U8) * (iInputCurrLength + BytesToCopy));
2824 
2825                 if (NULL != pTempNewBuffer)
2826                 {
2827                     // copy contents of the old buffer into the new one
2828                     oscl_memcpy(pTempNewBuffer, ipTempInputBuffer, iTempInputBufferLength);
2829                     // free the old buffer
2830                     if (ipTempInputBuffer)
2831                     {
2832                         oscl_free(ipTempInputBuffer);
2833                     }
2834                     // assign new one
2835                     ipTempInputBuffer = pTempNewBuffer;
2836 
2837                     pTempNewBuffer = NULL;
2838                     pTempNewBuffer = (OMX_U8*) oscl_malloc(sizeof(OMX_U8) * (iInputCurrLength + BytesToCopy));
2839 
2840                     // in the event that new buffer cannot be allocated
2841                     if (NULL == pTempNewBuffer)
2842                     {
2843                         // copy into what space is available, and let the decoder complain
2844                         BytesToCopy = iInputCurrLength - iInputCurrBufferSize;
2845                     }
2846                     else
2847                     {
2848                         // copy contents of the old buffer into the new one
2849                         oscl_memcpy(pTempNewBuffer, ipInputCurrBuffer, iInputCurrBufferSize);
2850                         // free the old buffer
2851                         if (ipInputCurrBuffer)
2852                         {
2853                             oscl_free(ipInputCurrBuffer);
2854                         }
2855                         // assign new memory location
2856                         ipInputCurrBuffer = pTempNewBuffer;
2857                         iInputCurrBufferSize = (iInputCurrLength + BytesToCopy);
2858                         ipFrameDecodeBuffer = ipInputCurrBuffer + iInputCurrLength;
2859                     }
2860                 }
2861                 //No memory to allocate ipTempInputBuffer
2862                 else
2863                 {
2864                     // copy into what space is available, and let the decoder complain
2865                     BytesToCopy = iInputCurrLength - iInputCurrBufferSize;
2866                 }
2867             }
2868 
2869             oscl_memcpy(ipFrameDecodeBuffer, (ipInputBuffer->pBuffer + ipInputBuffer->nOffset), BytesToCopy);
2870             ipFrameDecodeBuffer += ipInputBuffer->nFilledLen; // move the ptr
2871             iInputCurrLength += BytesToCopy;
2872 
2873             iFrameTimestamp = ipInputBuffer->nTimeStamp;
2874 
2875             // check if we've encountered end of frame flag while trying to assemble the very first frame
2876             if ((0 == iFrameCount) && ((ipInputBuffer->nFlags & OMX_BUFFERFLAG_ENDOFFRAME) != 0))
2877             {
2878                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtWithoutMarker EndOfFrameFlag finally arrived"));
2879                 iEndOfFrameFlag = OMX_TRUE;
2880             }
2881 
2882             if ((iInputCurrLength >= (iInputCurrBufferSize >> 1))
2883                     || (OMX_TRUE == iEndofStream) || (OMX_TRUE == iEndOfFrameFlag))
2884             {
2885                 break;
2886             }
2887 
2888             //Set the filled len to zero to indicate buffer is fully consumed
2889             ipInputBuffer->nFilledLen = 0;
2890             ReturnInputBuffer(ipInputBuffer, pInPort);
2891             ipInputBuffer = NULL;
2892 
2893             if (iNumInputBuffer > 0)
2894             {
2895                 ipInputBuffer = (OMX_BUFFERHEADERTYPE*) DeQueue(pInputQueue);
2896                 if (NULL == ipInputBuffer)
2897                 {
2898                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtWithoutMarker Error, Input buffer Dequeue returned NULL"));
2899                     return OMX_FALSE;
2900                 }
2901 
2902                 if (ipInputBuffer->nFlags & OMX_BUFFERFLAG_EOS)
2903                 {
2904                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtWithoutMarker EndOfStream arrived"));
2905                     iEndofStream = OMX_TRUE;
2906                 }
2907             }
2908         }
2909 
2910         if (iEndOfFrameFlag)
2911         {
2912             // if we have encountered end of frame, 1st frame has been assembled
2913             // and we can switch to "end of frame flag" mode
2914             iIsInputBufferEnded = OMX_FALSE;
2915             iNewInBufferRequired = OMX_FALSE;
2916             ipFrameDecodeBuffer = ipInputCurrBuffer; // rewind buffer ptr to beginning of inputcurrbuffer
2917             iPartialFrameAssembly = OMX_FALSE;
2918             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtWithoutMarker Found end of frame flag - OUT"));
2919             return OMX_TRUE;
2920 
2921         }
2922 
2923         if ((((iInputCurrLength + iTempInputBufferLength) < (iInputCurrBufferSize >> 1)))
2924                 && (OMX_TRUE != iEndofStream))
2925         {
2926             iPartialFrameAssembly = OMX_TRUE;
2927             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtWithoutMarker OUT"));
2928             return OMX_FALSE;
2929         }
2930         else
2931         {
2932             ipFrameDecodeBuffer = ipInputCurrBuffer;
2933             iPartialFrameAssembly = OMX_FALSE;
2934 
2935             /* Components not implementing ComponentBufferMgmtWithoutMarker(), will reset
2936              * iIsInputBufferEnded flag in the below routine */
2937             pOpenmaxAOType->ProcessInBufferFlag();
2938         }
2939 
2940     }
2941 
2942 
2943     //Different components may choose to do some extra processing here.
2944     //e.g. video components and also amr component copies the collected data into temp input buffers here.
2945     pOpenmaxAOType->ComponentBufferMgmtWithoutMarker();
2946 
2947     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : BufferMgmtWithoutMarker OUT"));
2948     return OMX_TRUE;
2949 
2950 }
2951 
2952 
2953 
2954 //Propagate here the buffer mark through output port in case of BufferMgmtWithoutMarker
ComponentBufferMgmtWithoutMarker()2955 OSCL_EXPORT_REF void OmxComponentBase::ComponentBufferMgmtWithoutMarker()
2956 {
2957     OMX_COMPONENTTYPE* pHandle = &iOmxComponent;
2958 
2959     ipTargetComponent = (OMX_COMPONENTTYPE*) ipInputBuffer->hMarkTargetComponent;
2960 
2961     iTargetMarkData = ipInputBuffer->pMarkData;
2962     if (ipTargetComponent == (OMX_COMPONENTTYPE*) pHandle)
2963     {
2964         (*(ipCallbacks->EventHandler))
2965         (pHandle,
2966          iCallbackData,
2967          OMX_EventMark,
2968          1,
2969          0,
2970          ipInputBuffer->pMarkData);
2971     }
2972 }
2973 
2974 
2975 /* A part of buffer management without marker routine, this function will
2976  * copy the current input buffer into a big temporary buffer, so that
2977  * an incomplete/partial frame is never passed to the decoder library for decode
2978 */
TempInputBufferMgmtWithoutMarker()2979 OSCL_EXPORT_REF void OmxComponentBase::TempInputBufferMgmtWithoutMarker()
2980 {
2981     OMX_COMPONENTTYPE* pHandle = &iOmxComponent;
2982     ComponentPortType*  pInPort = (ComponentPortType*) ipPorts[OMX_PORT_INPUTPORT_INDEX];
2983     OMX_U32 TempInputBufferSize = iInputCurrBufferSize;
2984 
2985     if (iTempInputBufferLength < (TempInputBufferSize >> 1))
2986     {
2987         oscl_memmove(ipTempInputBuffer, &ipTempInputBuffer[iTempConsumedLength], iTempInputBufferLength);
2988         iIsInputBufferEnded = OMX_TRUE;
2989         iTempConsumedLength = 0;
2990     }
2991 
2992     if ((iTempInputBufferLength + iTempConsumedLength + iInputCurrLength)
2993             <= TempInputBufferSize)
2994     {
2995         oscl_memcpy(&ipTempInputBuffer[iTempInputBufferLength + iTempConsumedLength], ipFrameDecodeBuffer, iInputCurrLength);
2996         iTempInputBufferLength += iInputCurrLength;
2997 
2998         if (iTempInputBufferLength + (TempInputBufferSize >> 1) <= TempInputBufferSize)
2999         {
3000             iNewInBufferRequired = OMX_TRUE;
3001         }
3002         else
3003         {
3004             iNewInBufferRequired = OMX_FALSE;
3005         }
3006 
3007         ipTargetComponent = (OMX_COMPONENTTYPE*) ipInputBuffer->hMarkTargetComponent;
3008 
3009         iTargetMarkData = ipInputBuffer->pMarkData;
3010         if (ipTargetComponent == (OMX_COMPONENTTYPE*) pHandle)
3011         {
3012             (*(ipCallbacks->EventHandler))
3013             (pHandle,
3014              iCallbackData,
3015              OMX_EventMark,
3016              1,
3017              0,
3018              ipInputBuffer->pMarkData);
3019         }
3020         ipInputBuffer->nFilledLen = 0;
3021         ReturnInputBuffer(ipInputBuffer, pInPort);
3022         ipInputBuffer = NULL;
3023 
3024     }
3025 
3026     if (iTempInputBufferLength >= (TempInputBufferSize >> 1))
3027     {
3028         iIsInputBufferEnded = OMX_FALSE;
3029     }
3030 }
3031 
3032 
3033 
Run()3034 OSCL_EXPORT_REF void OmxComponentBase::Run()
3035 {
3036     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : Run IN"));
3037 
3038     CoreMessage* pCoreMessage;
3039     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*) iOmxComponent.pComponentPrivate;
3040 
3041     //Execute the commands from the message handler queue
3042     if ((GetQueueNumElem(ipCoreDescriptor->pMessageQueue) > 0))
3043     {
3044         pCoreMessage = (CoreMessage*) DeQueue(ipCoreDescriptor->pMessageQueue);
3045 
3046         if (OMX_CommandStateSet == pCoreMessage->MessageParam1)
3047         {
3048             if (OMX_StateExecuting == pCoreMessage->MessageParam2)
3049             {
3050                 iBufferExecuteFlag = OMX_TRUE;
3051             }
3052             else
3053             {
3054                 iBufferExecuteFlag = OMX_FALSE;
3055             }
3056         }
3057 
3058         MessageHandler(pCoreMessage);
3059 
3060         /* If some allocations/deallocations are required before the state transition
3061          * then queue the command again to be executed later on
3062          */
3063         if (OMX_TRUE == iStateTransitionFlag)
3064         {
3065             if (OMX_ErrorNone != Queue(ipCoreDescriptor->pMessageQueue, pCoreMessage))
3066             {
3067                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : Error, Queue command failed, Run OUT"));
3068                 return;
3069             }
3070 
3071             // Don't reschedule. Wait for arriving buffers to do it
3072             //RunIfNotReady();
3073             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : Run OUT"));
3074             return;
3075         }
3076 
3077         else
3078         {
3079             oscl_free(pCoreMessage);
3080             pCoreMessage = NULL;
3081         }
3082     }
3083 
3084     /* If the component is in executing state, call the Buffer management function.
3085      * Stop calling this function as soon as state transition request is received.
3086      */
3087     if ((OMX_TRUE == iBufferExecuteFlag) && (OMX_TRUE != iResizePending))
3088     {
3089         pOpenmaxAOType->BufferMgmtFunction();
3090     }
3091 
3092     //Check for any more commands in the message handler queue & schedule them for later
3093     if ((GetQueueNumElem(ipCoreDescriptor->pMessageQueue) > 0))
3094     {
3095         RunIfNotReady();
3096     }
3097 
3098 
3099     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentBase : Run OUT"));
3100 
3101     return;
3102 }
3103 
3104 
3105 /**************************
3106  AUDIO BASE CLASS ROUTINES
3107  **************************/
OmxComponentAudio()3108 OSCL_EXPORT_REF OmxComponentAudio::OmxComponentAudio()
3109 {
3110     iIsAudioComponent = OMX_TRUE;
3111 
3112 }
3113 
3114 
GetParameter(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nParamIndex,OMX_INOUT OMX_PTR ComponentParameterStructure)3115 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentAudio::GetParameter(
3116     OMX_IN  OMX_HANDLETYPE hComponent,
3117     OMX_IN  OMX_INDEXTYPE nParamIndex,
3118     OMX_INOUT OMX_PTR ComponentParameterStructure)
3119 {
3120     OSCL_UNUSED_ARG(hComponent);
3121 
3122     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter IN"));
3123 
3124     OMX_PRIORITYMGMTTYPE* pPrioMgmt;
3125     OMX_PARAM_BUFFERSUPPLIERTYPE* pBufSupply;
3126     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef;
3127     OMX_PORT_PARAM_TYPE* pPortDomains;
3128     OMX_U32 PortIndex;
3129 
3130     OMX_AUDIO_PARAM_PORTFORMATTYPE* pAudioPortFormat;
3131     OMX_AUDIO_PARAM_PCMMODETYPE* pAudioPcmMode;
3132     OMX_AUDIO_PARAM_WMATYPE* pAudioWma;
3133     OMX_AUDIO_PARAM_MP3TYPE* pAudioMp3;
3134     OMX_AUDIO_CONFIG_EQUALIZERTYPE* pAudioEqualizer;
3135     OMX_AUDIO_PARAM_AACPROFILETYPE* pAudioAac;
3136     OMX_AUDIO_PARAM_AMRTYPE* pAudioAmr;
3137 
3138     ComponentPortType* pComponentPort;
3139 
3140     if (NULL == ComponentParameterStructure)
3141     {
3142         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter error bad parameter"));
3143         return OMX_ErrorBadParameter;
3144     }
3145 
3146     switch (nParamIndex)
3147     {
3148         case OMX_IndexParamPriorityMgmt:
3149         {
3150             pPrioMgmt = (OMX_PRIORITYMGMTTYPE*) ComponentParameterStructure;
3151             SetHeader(pPrioMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
3152             pPrioMgmt->nGroupPriority = iGroupPriority;
3153             pPrioMgmt->nGroupID = iGroupID;
3154         }
3155         break;
3156 
3157         case OMX_IndexParamAudioInit:
3158         {
3159             SetHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE));
3160             oscl_memcpy(ComponentParameterStructure, &iPortTypesParam, sizeof(OMX_PORT_PARAM_TYPE));
3161         }
3162         break;
3163 
3164 
3165         //Following 3 cases have a single common piece of code to be executed
3166         case OMX_IndexParamVideoInit:
3167         case OMX_IndexParamImageInit:
3168         case OMX_IndexParamOtherInit:
3169         {
3170             pPortDomains = (OMX_PORT_PARAM_TYPE*) ComponentParameterStructure;
3171             SetHeader(pPortDomains, sizeof(OMX_PORT_PARAM_TYPE));
3172             pPortDomains->nPorts = 0;
3173             pPortDomains->nStartPortNumber = 0;
3174         }
3175         break;
3176 
3177         case OMX_IndexParamAudioPortFormat:
3178         {
3179             pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*) ComponentParameterStructure;
3180             //Added to pass parameter test
3181             if (pAudioPortFormat->nIndex > ipPorts[pAudioPortFormat->nPortIndex]->AudioParam.nIndex)
3182             {
3183                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter error index out of range"));
3184                 return OMX_ErrorNoMore;
3185             }
3186             SetHeader(pAudioPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
3187             if (pAudioPortFormat->nPortIndex <= 1)
3188             {
3189                 pComponentPort = (ComponentPortType*) ipPorts[pAudioPortFormat->nPortIndex];
3190                 oscl_memcpy(pAudioPortFormat, &pComponentPort->AudioParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
3191             }
3192             else
3193             {
3194                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter error bad port index"));
3195                 return OMX_ErrorBadPortIndex;
3196             }
3197         }
3198         break;
3199 
3200         case OMX_IndexParamAudioPcm:
3201         {
3202             pAudioPcmMode = (OMX_AUDIO_PARAM_PCMMODETYPE*) ComponentParameterStructure;
3203             if (pAudioPcmMode->nPortIndex > 1)
3204             {
3205                 return OMX_ErrorBadPortIndex;
3206             }
3207             PortIndex = pAudioPcmMode->nPortIndex;
3208             oscl_memcpy(pAudioPcmMode, &ipPorts[PortIndex]->AudioPcmMode, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
3209             SetHeader(pAudioPcmMode, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
3210         }
3211         break;
3212 
3213         case OMX_IndexParamAudioMp3:
3214         {
3215             pAudioMp3 = (OMX_AUDIO_PARAM_MP3TYPE*) ComponentParameterStructure;
3216             if (pAudioMp3->nPortIndex != iCompressedFormatPortNum)
3217             {
3218                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter error bad port index"));
3219                 return OMX_ErrorBadPortIndex;
3220             }
3221             PortIndex = pAudioMp3->nPortIndex;
3222             oscl_memcpy(pAudioMp3, &ipPorts[PortIndex]->AudioMp3Param, sizeof(OMX_AUDIO_PARAM_MP3TYPE));
3223             SetHeader(pAudioMp3, sizeof(OMX_AUDIO_PARAM_MP3TYPE));
3224         }
3225         break;
3226 
3227         case OMX_IndexParamAudioWma:
3228         {
3229             pAudioWma = (OMX_AUDIO_PARAM_WMATYPE*) ComponentParameterStructure;
3230             if (pAudioWma->nPortIndex != iCompressedFormatPortNum)
3231             {
3232                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter error bad port index"));
3233                 return OMX_ErrorBadPortIndex;
3234             }
3235             PortIndex = pAudioWma->nPortIndex;
3236             oscl_memcpy(pAudioWma, &ipPorts[PortIndex]->AudioWmaParam, sizeof(OMX_AUDIO_PARAM_WMATYPE));
3237             SetHeader(pAudioWma, sizeof(OMX_AUDIO_PARAM_WMATYPE));
3238         }
3239         break;
3240 
3241         case OMX_IndexConfigAudioEqualizer:
3242         {
3243             pAudioEqualizer = (OMX_AUDIO_CONFIG_EQUALIZERTYPE*) ComponentParameterStructure;
3244             if (pAudioEqualizer->nPortIndex != iCompressedFormatPortNum)
3245             {
3246                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter error bad port index"));
3247                 return OMX_ErrorBadPortIndex;
3248             }
3249             PortIndex = pAudioEqualizer->nPortIndex;
3250             oscl_memcpy(pAudioEqualizer, &ipPorts[PortIndex]->AudioEqualizerType, sizeof(OMX_AUDIO_CONFIG_EQUALIZERTYPE));
3251             SetHeader(pAudioEqualizer, sizeof(OMX_AUDIO_CONFIG_EQUALIZERTYPE));
3252         }
3253         break;
3254 
3255         case OMX_IndexParamAudioAac:
3256         {
3257             pAudioAac = (OMX_AUDIO_PARAM_AACPROFILETYPE*) ComponentParameterStructure;
3258             if (pAudioAac->nPortIndex != iCompressedFormatPortNum)
3259             {
3260                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter error bad port index"));
3261                 return OMX_ErrorBadPortIndex;
3262             }
3263             PortIndex = pAudioAac->nPortIndex;
3264             oscl_memcpy(pAudioAac, &ipPorts[PortIndex]->AudioAacParam, sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE));
3265             SetHeader(pAudioAac, sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE));
3266         }
3267         break;
3268 
3269         case OMX_IndexParamAudioAmr:
3270         {
3271             pAudioAmr = (OMX_AUDIO_PARAM_AMRTYPE*) ComponentParameterStructure;
3272             if (pAudioAmr->nPortIndex != iCompressedFormatPortNum)
3273             {
3274                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter error bad port index"));
3275                 return OMX_ErrorBadPortIndex;
3276             }
3277             PortIndex = pAudioAmr->nPortIndex;
3278             oscl_memcpy(pAudioAmr, &ipPorts[PortIndex]->AudioAmrParam, sizeof(OMX_AUDIO_PARAM_AMRTYPE));
3279             SetHeader(pAudioAmr, sizeof(OMX_AUDIO_PARAM_AMRTYPE));
3280         }
3281         break;
3282 
3283         case OMX_IndexParamPortDefinition:
3284         {
3285             pPortDef  = (OMX_PARAM_PORTDEFINITIONTYPE*) ComponentParameterStructure;
3286             PortIndex = pPortDef->nPortIndex;
3287             if (PortIndex >= iNumPorts)
3288             {
3289                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter error bad port index"));
3290                 return OMX_ErrorBadPortIndex;
3291             }
3292             oscl_memcpy(pPortDef, &ipPorts[PortIndex]->PortParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
3293         }
3294         break;
3295 
3296         case OMX_IndexParamCompBufferSupplier:
3297         {
3298             pBufSupply = (OMX_PARAM_BUFFERSUPPLIERTYPE*) ComponentParameterStructure;
3299             PortIndex = pBufSupply->nPortIndex;
3300             if (PortIndex >= iNumPorts)
3301             {
3302                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter error bad port index"));
3303                 return OMX_ErrorBadPortIndex;
3304             }
3305             SetHeader(pBufSupply, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
3306 
3307             if (OMX_DirInput == ipPorts[PortIndex]->PortParam.eDir)
3308             {
3309                 pBufSupply->eBufferSupplier = OMX_BufferSupplyUnspecified;
3310             }
3311             else
3312             {
3313                 SetHeader(pBufSupply, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
3314                 pBufSupply->eBufferSupplier = OMX_BufferSupplyUnspecified;
3315             }
3316         }
3317         break;
3318 
3319         case(OMX_INDEXTYPE) PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX:
3320         {
3321             PV_OMXComponentCapabilityFlagsType *pCap_flags = (PV_OMXComponentCapabilityFlagsType *) ComponentParameterStructure;
3322             if (NULL == pCap_flags)
3323             {
3324                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter error pCap_flags NULL"));
3325                 return OMX_ErrorBadParameter;
3326             }
3327             oscl_memcpy(pCap_flags, &iPVCapabilityFlags, sizeof(iPVCapabilityFlags));
3328 
3329         }
3330         break;
3331 
3332         default:
3333         {
3334             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter error Unsupported Index"));
3335             return OMX_ErrorUnsupportedIndex;
3336         }
3337     }
3338 
3339     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : GetParameter OUT"));
3340 
3341     return OMX_ErrorNone;
3342 
3343 }
3344 
3345 
SetParameter(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nParamIndex,OMX_IN OMX_PTR ComponentParameterStructure)3346 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentAudio::SetParameter(
3347     OMX_IN  OMX_HANDLETYPE hComponent,
3348     OMX_IN  OMX_INDEXTYPE nParamIndex,
3349     OMX_IN  OMX_PTR ComponentParameterStructure)
3350 {
3351     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter IN"));
3352 
3353     OMX_PRIORITYMGMTTYPE* pPrioMgmt;
3354     OMX_AUDIO_PARAM_PORTFORMATTYPE* pAudioPortFormat;
3355     OMX_AUDIO_PARAM_PCMMODETYPE* pAudioPcmMode;
3356     OMX_PARAM_BUFFERSUPPLIERTYPE* pBufSupply;
3357     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef ;
3358     OMX_PARAM_COMPONENTROLETYPE* pCompRole;
3359     ComponentPortType* pComponentPort;
3360 
3361     OMX_AUDIO_PARAM_WMATYPE* pAudioWma;
3362     OMX_AUDIO_PARAM_MP3TYPE* pAudioMp3;
3363     OMX_AUDIO_CONFIG_EQUALIZERTYPE* pAudioEqualizer;
3364     OMX_AUDIO_PARAM_AACPROFILETYPE* pAudioAac;
3365     OMX_AUDIO_PARAM_AMRTYPE* pAudioAmr;
3366 
3367     OMX_U32 PortIndex;
3368     OMX_ERRORTYPE ErrorType = OMX_ErrorNone;
3369     OmxComponentAudio* pOpenmaxAOType = (OmxComponentAudio*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
3370 
3371 
3372     if (NULL == ComponentParameterStructure)
3373     {
3374         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error bad parameter"));
3375         return OMX_ErrorBadParameter;
3376     }
3377 
3378     switch (nParamIndex)
3379     {
3380         case OMX_IndexParamAudioInit:
3381         {
3382             /*Check Structure Header*/
3383             CheckHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE));
3384             if (ErrorType != OMX_ErrorNone)
3385             {
3386                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error audio init failed"));
3387                 return ErrorType;
3388             }
3389             oscl_memcpy(&iPortTypesParam, ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE));
3390         }
3391         break;
3392 
3393         case OMX_IndexParamAudioPortFormat:
3394         {
3395             pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*) ComponentParameterStructure;
3396             PortIndex = pAudioPortFormat->nPortIndex;
3397             /*Check Structure Header and verify component state*/
3398             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pAudioPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
3399             if (ErrorType != OMX_ErrorNone)
3400             {
3401                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error parameter sanity check error"));
3402                 return ErrorType;
3403             }
3404             if (PortIndex <= 1)
3405             {
3406                 pComponentPort = (ComponentPortType*) ipPorts[PortIndex];
3407                 oscl_memcpy(&pComponentPort->AudioParam, pAudioPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
3408             }
3409             else
3410             {
3411                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error bad port index"));
3412                 return OMX_ErrorBadPortIndex;
3413             }
3414         }
3415         break;
3416 
3417         case OMX_IndexParamAudioPcm:
3418         {
3419             pAudioPcmMode = (OMX_AUDIO_PARAM_PCMMODETYPE*) ComponentParameterStructure;
3420             PortIndex = pAudioPcmMode->nPortIndex;
3421             /*Check Structure Header and verify component State*/
3422             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pAudioPcmMode, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
3423             oscl_memcpy(&ipPorts[PortIndex]->AudioPcmMode, pAudioPcmMode, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
3424         }
3425         break;
3426 
3427         case OMX_IndexParamAudioMp3:
3428         {
3429             pAudioMp3 = (OMX_AUDIO_PARAM_MP3TYPE*) ComponentParameterStructure;
3430             PortIndex = pAudioMp3->nPortIndex;
3431             /*Check Structure Header and verify component state*/
3432             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pAudioMp3, sizeof(OMX_AUDIO_PARAM_MP3TYPE));
3433             if (ErrorType != OMX_ErrorNone)
3434             {
3435                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error parameter sanity check error"));
3436                 return ErrorType;
3437             }
3438             oscl_memcpy(&ipPorts[PortIndex]->AudioMp3Param, pAudioMp3, sizeof(OMX_AUDIO_PARAM_MP3TYPE));
3439         }
3440         break;
3441 
3442         case OMX_IndexParamAudioWma:
3443         {
3444 
3445 
3446             pAudioWma = (OMX_AUDIO_PARAM_WMATYPE*) ComponentParameterStructure;
3447             PortIndex = pAudioWma->nPortIndex;
3448             /*Check Structure Header and verify component state*/
3449             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pAudioWma, sizeof(OMX_AUDIO_PARAM_WMATYPE));
3450             if (ErrorType != OMX_ErrorNone)
3451             {
3452                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error parameter sanity check error"));
3453                 return ErrorType;
3454             }
3455             oscl_memcpy(&ipPorts[PortIndex]->AudioWmaParam, pAudioWma, sizeof(OMX_AUDIO_PARAM_WMATYPE));
3456         }
3457         break;
3458 
3459         case OMX_IndexConfigAudioEqualizer:
3460         {
3461             pAudioEqualizer = (OMX_AUDIO_CONFIG_EQUALIZERTYPE*) ComponentParameterStructure;
3462             PortIndex = pAudioEqualizer->nPortIndex;
3463             /*Check Structure Header and verify component state*/
3464             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pAudioEqualizer, sizeof(OMX_AUDIO_CONFIG_EQUALIZERTYPE));
3465             if (ErrorType != OMX_ErrorNone)
3466             {
3467                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error parameter sanity check error"));
3468                 return ErrorType;
3469             }
3470             oscl_memcpy(&ipPorts[PortIndex]->AudioEqualizerType, pAudioEqualizer, sizeof(OMX_AUDIO_CONFIG_EQUALIZERTYPE));
3471         }
3472         break;
3473 
3474         case OMX_IndexParamAudioAac:
3475         {
3476             OMX_BOOL AacPlusFlag = OMX_TRUE;
3477 
3478             pAudioAac = (OMX_AUDIO_PARAM_AACPROFILETYPE*) ComponentParameterStructure;
3479             PortIndex = pAudioAac->nPortIndex;
3480             /*Check Structure Header and verify component state*/
3481             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pAudioAac, sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE));
3482             if (ErrorType != OMX_ErrorNone)
3483             {
3484                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error parameter sanity check error"));
3485                 return ErrorType;
3486             }
3487             oscl_memcpy(&ipPorts[PortIndex]->AudioAacParam, pAudioAac, sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE));
3488 
3489             if ((ipPorts[PortIndex]->AudioAacParam.eAACProfile == OMX_AUDIO_AACObjectHE)
3490                     || (ipPorts[PortIndex]->AudioAacParam.eAACProfile == OMX_AUDIO_AACObjectHE_PS))
3491             {
3492                 AacPlusFlag = OMX_TRUE;
3493             }
3494             else
3495             {
3496                 AacPlusFlag = OMX_FALSE;
3497             }
3498 
3499             pOpenmaxAOType->UpdateAACPlusFlag(AacPlusFlag);
3500         }
3501         break;
3502 
3503         case OMX_IndexParamAudioAmr:
3504         {
3505             pAudioAmr = (OMX_AUDIO_PARAM_AMRTYPE*) ComponentParameterStructure;
3506             PortIndex = pAudioAmr->nPortIndex;
3507             /*Check Structure Header and verify component state*/
3508             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pAudioAmr, sizeof(OMX_AUDIO_PARAM_AMRTYPE));
3509             if (ErrorType != OMX_ErrorNone)
3510             {
3511                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error parameter sanity check error"));
3512                 return ErrorType;
3513             }
3514             oscl_memcpy(&ipPorts[PortIndex]->AudioAmrParam, pAudioAmr, sizeof(OMX_AUDIO_PARAM_AMRTYPE));
3515 
3516             //If the band mode turns out to be WB, set the sampling freq to 16KHz
3517             if ((pAudioAmr->eAMRBandMode >= OMX_AUDIO_AMRBandModeWB0) &&
3518                     (pAudioAmr->eAMRBandMode <= OMX_AUDIO_AMRBandModeWB8))
3519             {
3520                 ipPorts[OMX_PORT_OUTPUTPORT_INDEX]->AudioPcmMode.nSamplingRate = 16000;
3521             }
3522         }
3523         break;
3524 
3525         case OMX_IndexParamPriorityMgmt:
3526         {
3527             if (iState != OMX_StateLoaded && iState != OMX_StateWaitForResources)
3528             {
3529                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error incorrect state error"));
3530                 return OMX_ErrorIncorrectStateOperation;
3531             }
3532             pPrioMgmt = (OMX_PRIORITYMGMTTYPE*) ComponentParameterStructure;
3533             if ((ErrorType = CheckHeader(pPrioMgmt, sizeof(OMX_PRIORITYMGMTTYPE))) != OMX_ErrorNone)
3534             {
3535                 break;
3536             }
3537             iGroupPriority = pPrioMgmt->nGroupPriority;
3538             iGroupID = pPrioMgmt->nGroupID;
3539         }
3540         break;
3541 
3542         case OMX_IndexParamPortDefinition:
3543         {
3544             pPortDef  = (OMX_PARAM_PORTDEFINITIONTYPE*) ComponentParameterStructure;
3545             PortIndex = pPortDef->nPortIndex;
3546 
3547             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
3548             if (ErrorType != OMX_ErrorNone)
3549             {
3550                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error parameter sanity check error"));
3551                 return ErrorType;
3552             }
3553 
3554             ipPorts[PortIndex]->PortParam.nBufferCountActual = pPortDef->nBufferCountActual;
3555             ipPorts[PortIndex]->PortParam.nBufferSize = pPortDef->nBufferSize;
3556 
3557             oscl_memcpy(&ipPorts[PortIndex]->PortParam.format.audio, &pPortDef->format.audio, sizeof(OMX_AUDIO_PORTDEFINITIONTYPE));
3558         }
3559         break;
3560 
3561         case OMX_IndexParamCompBufferSupplier:
3562         {
3563             pBufSupply = (OMX_PARAM_BUFFERSUPPLIERTYPE*) ComponentParameterStructure;
3564             PortIndex = pBufSupply->nPortIndex;
3565 
3566             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pBufSupply, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
3567             if (OMX_ErrorIncorrectStateOperation == ErrorType)
3568             {
3569                 if (PORT_IS_ENABLED(ipPorts[pBufSupply->nPortIndex]))
3570                 {
3571                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error incorrect state error"));
3572                     return OMX_ErrorIncorrectStateOperation;
3573                 }
3574             }
3575             else if (ErrorType != OMX_ErrorNone)
3576             {
3577                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error parameter sanity check error"));
3578                 return ErrorType;
3579             }
3580 
3581             if (pBufSupply->eBufferSupplier == OMX_BufferSupplyUnspecified)
3582             {
3583                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter OUT"));
3584                 return OMX_ErrorNone;
3585             }
3586 
3587             ErrorType = OMX_ErrorNone;
3588         }
3589         break;
3590 
3591         case OMX_IndexParamStandardComponentRole:
3592         {
3593             pCompRole = (OMX_PARAM_COMPONENTROLETYPE*) ComponentParameterStructure;
3594             if ((ErrorType = CheckHeader(pCompRole, sizeof(OMX_PARAM_COMPONENTROLETYPE))) != OMX_ErrorNone)
3595             {
3596                 break;
3597             }
3598             oscl_strncpy((OMX_STRING)iComponentRole, (OMX_STRING)pCompRole->cRole, OMX_MAX_STRINGNAME_SIZE);
3599             iComponentRoleFlag = OMX_TRUE;
3600         }
3601         break;
3602 
3603 
3604         default:
3605         {
3606             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter error Unsupported index"));
3607             return OMX_ErrorUnsupportedIndex;
3608         }
3609     }
3610 
3611     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentAudio : SetParameter OUT"));
3612     return ErrorType;
3613 
3614 }
3615 
3616 
3617 /*************************
3618  VIDEO BASE CLASS ROUTINES
3619  *************************/
OmxComponentVideo()3620 OSCL_EXPORT_REF OmxComponentVideo::OmxComponentVideo()
3621 {
3622     iIsAudioComponent = OMX_FALSE;
3623 
3624 }
3625 
3626 
GetParameter(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nParamIndex,OMX_INOUT OMX_PTR ComponentParameterStructure)3627 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentVideo::GetParameter(
3628     OMX_IN  OMX_HANDLETYPE hComponent,
3629     OMX_IN  OMX_INDEXTYPE nParamIndex,
3630     OMX_INOUT OMX_PTR ComponentParameterStructure)
3631 {
3632     OSCL_UNUSED_ARG(hComponent);
3633 
3634     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter IN"));
3635 
3636     OMX_PRIORITYMGMTTYPE* pPrioMgmt;
3637     OMX_PARAM_BUFFERSUPPLIERTYPE* pBufSupply;
3638     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef;
3639     OMX_PORT_PARAM_TYPE* pPortDomains;
3640     OMX_U32 PortIndex;
3641 
3642     OMX_VIDEO_PARAM_PORTFORMATTYPE* pVideoPortFormat;
3643     OMX_VIDEO_PARAM_PROFILELEVELTYPE* pProfileLevel;
3644 
3645     OMX_VIDEO_PARAM_MPEG4TYPE* pVideoMpeg4;
3646     OMX_VIDEO_PARAM_H263TYPE* pVideoH263;
3647     OMX_VIDEO_PARAM_AVCTYPE* pVideoAvc;
3648     OMX_VIDEO_PARAM_WMVTYPE* pVideoWmv;
3649 
3650     //Video encoder configuration parameters
3651     OMX_CONFIG_ROTATIONTYPE*             pVideoRotation;
3652     OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* pVideoErrCorr;
3653     OMX_VIDEO_PARAM_BITRATETYPE*         pVideoRateControl;
3654     OMX_VIDEO_PARAM_QUANTIZATIONTYPE*    pVideoQuant;
3655     OMX_VIDEO_PARAM_VBSMCTYPE*           pVideoBlock;
3656     OMX_VIDEO_PARAM_MOTIONVECTORTYPE*    pVideoMotionVector;
3657     OMX_VIDEO_PARAM_INTRAREFRESHTYPE*    pVideoIntraRefresh;
3658 
3659     if (NULL == ComponentParameterStructure)
3660     {
3661         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad parameter"));
3662         return OMX_ErrorBadParameter;
3663     }
3664 
3665     switch (nParamIndex)
3666     {
3667         case OMX_IndexParamPriorityMgmt:
3668         {
3669             pPrioMgmt = (OMX_PRIORITYMGMTTYPE*) ComponentParameterStructure;
3670             SetHeader(pPrioMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
3671             pPrioMgmt->nGroupPriority = iGroupPriority;
3672             pPrioMgmt->nGroupID = iGroupID;
3673         }
3674         break;
3675 
3676         case OMX_IndexParamVideoInit:
3677         {
3678             SetHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE));
3679             oscl_memcpy(ComponentParameterStructure, &iPortTypesParam, sizeof(OMX_PORT_PARAM_TYPE));
3680         }
3681         break;
3682 
3683 
3684         //Following 3 cases have a single common piece of code to be executed
3685         case OMX_IndexParamAudioInit:
3686         case OMX_IndexParamImageInit:
3687         case OMX_IndexParamOtherInit:
3688         {
3689             pPortDomains = (OMX_PORT_PARAM_TYPE*) ComponentParameterStructure;
3690             SetHeader(pPortDomains, sizeof(OMX_PORT_PARAM_TYPE));
3691             pPortDomains->nPorts = 0;
3692             pPortDomains->nStartPortNumber = 0;
3693         }
3694         break;
3695 
3696         case OMX_IndexParamVideoPortFormat:
3697         {
3698             pVideoPortFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE*) ComponentParameterStructure;
3699 
3700             //Check for valid port index
3701             PortIndex = pVideoPortFormat->nPortIndex;
3702             if (PortIndex >= iNumPorts)
3703             {
3704                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3705                 return OMX_ErrorBadPortIndex;
3706             }
3707 
3708             OMX_U32 QueriedIndex = pVideoPortFormat->nIndex;
3709             if (QueriedIndex >= ipPorts[PortIndex]->ActualNumPortFormatsSupported)
3710             {
3711                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error index out of range"));
3712                 return OMX_ErrorNoMore;
3713             }
3714             else
3715             {
3716                 SetHeader(pVideoPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
3717                 oscl_memcpy(pVideoPortFormat, &ipPorts[PortIndex]->VideoParam[QueriedIndex], sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
3718             }
3719         }
3720 
3721         break;
3722 
3723         case OMX_IndexParamVideoMpeg4:
3724         {
3725             pVideoMpeg4 = (OMX_VIDEO_PARAM_MPEG4TYPE*) ComponentParameterStructure;
3726             if (pVideoMpeg4->nPortIndex != iCompressedFormatPortNum)
3727             {
3728                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3729                 return OMX_ErrorBadPortIndex;
3730             }
3731             PortIndex = pVideoMpeg4->nPortIndex;
3732             oscl_memcpy(pVideoMpeg4, &ipPorts[PortIndex]->VideoMpeg4, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
3733             SetHeader(pVideoMpeg4, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
3734         }
3735         break;
3736 
3737         case OMX_IndexParamVideoH263:
3738         {
3739             pVideoH263 = (OMX_VIDEO_PARAM_H263TYPE*) ComponentParameterStructure;
3740             if (pVideoH263->nPortIndex != iCompressedFormatPortNum)
3741             {
3742                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3743                 return OMX_ErrorBadPortIndex;
3744             }
3745             PortIndex = pVideoH263->nPortIndex;
3746             oscl_memcpy(pVideoH263, &ipPorts[PortIndex]->VideoH263, sizeof(OMX_VIDEO_PARAM_H263TYPE));
3747             SetHeader(pVideoH263, sizeof(OMX_VIDEO_PARAM_H263TYPE));
3748         }
3749         break;
3750 
3751         case OMX_IndexParamVideoAvc:
3752         {
3753             pVideoAvc = (OMX_VIDEO_PARAM_AVCTYPE*) ComponentParameterStructure;
3754             if (pVideoAvc->nPortIndex != iCompressedFormatPortNum)
3755             {
3756                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3757                 return OMX_ErrorBadPortIndex;
3758             }
3759             PortIndex = pVideoAvc->nPortIndex;
3760             oscl_memcpy(pVideoAvc, &ipPorts[PortIndex]->VideoAvc, sizeof(OMX_VIDEO_PARAM_AVCTYPE));
3761             SetHeader(pVideoAvc, sizeof(OMX_VIDEO_PARAM_AVCTYPE));
3762         }
3763         break;
3764 
3765         case OMX_IndexParamVideoWmv:
3766         {
3767             pVideoWmv = (OMX_VIDEO_PARAM_WMVTYPE*)ComponentParameterStructure;
3768             if (pVideoWmv->nPortIndex != iCompressedFormatPortNum)
3769             {
3770                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3771                 return OMX_ErrorBadPortIndex;
3772             }
3773             PortIndex = pVideoWmv->nPortIndex;
3774             oscl_memcpy(pVideoWmv, &ipPorts[PortIndex]->VideoWmv, sizeof(OMX_VIDEO_PARAM_WMVTYPE));
3775             SetHeader(pVideoWmv, sizeof(OMX_VIDEO_PARAM_WMVTYPE));
3776         }
3777         break;
3778 
3779         case OMX_IndexParamVideoProfileLevelQuerySupported:
3780         {
3781             pProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*) ComponentParameterStructure;
3782 
3783             PortIndex = pProfileLevel->nPortIndex;
3784             if (pProfileLevel->nProfileIndex > ipPorts[PortIndex]->ProfileLevel.nProfileIndex)
3785             {
3786                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error profile not supported"));
3787                 return OMX_ErrorNoMore;
3788             }
3789 
3790             oscl_memcpy(pProfileLevel, &ipPorts[PortIndex]->ProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE));
3791             SetHeader(pProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE));
3792         }
3793         break;
3794 
3795         case OMX_IndexParamVideoProfileLevelCurrent:
3796         {
3797             pProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*) ComponentParameterStructure;
3798 
3799             PortIndex = pProfileLevel->nPortIndex;
3800 
3801             oscl_memcpy(pProfileLevel, &ipPorts[PortIndex]->ProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE));
3802             SetHeader(pProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE));
3803         }
3804         break;
3805 
3806         case OMX_IndexParamPortDefinition:
3807         {
3808             pPortDef  = (OMX_PARAM_PORTDEFINITIONTYPE*) ComponentParameterStructure;
3809             PortIndex = pPortDef->nPortIndex;
3810             if (PortIndex >= iNumPorts)
3811             {
3812                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3813                 return OMX_ErrorBadPortIndex;
3814             }
3815             oscl_memcpy(pPortDef, &ipPorts[PortIndex]->PortParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
3816         }
3817         break;
3818 
3819         case OMX_IndexParamCompBufferSupplier:
3820         {
3821             pBufSupply = (OMX_PARAM_BUFFERSUPPLIERTYPE*) ComponentParameterStructure;
3822             PortIndex = pBufSupply->nPortIndex;
3823             if (PortIndex >= iNumPorts)
3824             {
3825                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3826                 return OMX_ErrorBadPortIndex;
3827             }
3828             SetHeader(pBufSupply, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
3829 
3830             if (OMX_DirInput == ipPorts[PortIndex]->PortParam.eDir)
3831             {
3832                 pBufSupply->eBufferSupplier = OMX_BufferSupplyUnspecified;
3833             }
3834             else
3835             {
3836                 SetHeader(pBufSupply, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
3837                 pBufSupply->eBufferSupplier = OMX_BufferSupplyUnspecified;
3838             }
3839         }
3840         break;
3841 
3842         case(OMX_INDEXTYPE) PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX:
3843         {
3844             PV_OMXComponentCapabilityFlagsType *pCap_flags = (PV_OMXComponentCapabilityFlagsType *) ComponentParameterStructure;
3845             if (NULL == pCap_flags)
3846             {
3847                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error pCap_flags NULL"));
3848                 return OMX_ErrorBadParameter;
3849             }
3850             oscl_memcpy(pCap_flags, &iPVCapabilityFlags, sizeof(iPVCapabilityFlags));
3851 
3852         }
3853         break;
3854 
3855         case OMX_IndexConfigCommonRotate:
3856         {
3857             pVideoRotation = (OMX_CONFIG_ROTATIONTYPE*) ComponentParameterStructure;
3858             if (pVideoRotation->nPortIndex >= iNumPorts)
3859             {
3860                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3861                 return OMX_ErrorBadPortIndex;
3862             }
3863             PortIndex = pVideoRotation->nPortIndex;
3864             oscl_memcpy(pVideoRotation, &ipPorts[PortIndex]->VideoOrientationType, sizeof(OMX_CONFIG_ROTATIONTYPE));
3865             SetHeader(pVideoRotation, sizeof(OMX_CONFIG_ROTATIONTYPE));
3866         }
3867         break;
3868 
3869         case OMX_IndexParamVideoErrorCorrection:
3870         {
3871             pVideoErrCorr = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE*) ComponentParameterStructure;
3872             if (pVideoErrCorr->nPortIndex != iCompressedFormatPortNum)
3873             {
3874                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3875                 return OMX_ErrorBadPortIndex;
3876             }
3877             PortIndex = pVideoErrCorr->nPortIndex;
3878             oscl_memcpy(pVideoErrCorr, &ipPorts[PortIndex]->VideoErrorCorrection, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));
3879             SetHeader(pVideoErrCorr, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));
3880         }
3881         break;
3882 
3883         case OMX_IndexParamVideoBitrate:
3884         {
3885             pVideoRateControl = (OMX_VIDEO_PARAM_BITRATETYPE*) ComponentParameterStructure;
3886             if (pVideoRateControl->nPortIndex != iCompressedFormatPortNum)
3887             {
3888                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3889                 return OMX_ErrorBadPortIndex;
3890             }
3891             PortIndex = pVideoRateControl->nPortIndex;
3892             oscl_memcpy(pVideoRateControl, &ipPorts[PortIndex]->VideoRateType, sizeof(OMX_VIDEO_PARAM_BITRATETYPE));
3893             SetHeader(pVideoRateControl, sizeof(OMX_VIDEO_PARAM_BITRATETYPE));
3894         }
3895         break;
3896 
3897         case OMX_IndexParamVideoQuantization:
3898         {
3899             pVideoQuant = (OMX_VIDEO_PARAM_QUANTIZATIONTYPE*) ComponentParameterStructure;
3900             if (pVideoQuant->nPortIndex != iCompressedFormatPortNum)
3901             {
3902                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3903                 return OMX_ErrorBadPortIndex;
3904             }
3905             PortIndex = pVideoQuant->nPortIndex;
3906             oscl_memcpy(pVideoQuant, &ipPorts[PortIndex]->VideoQuantType, sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE));
3907             SetHeader(pVideoQuant, sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE));
3908         }
3909         break;
3910 
3911         case OMX_IndexParamVideoVBSMC:
3912         {
3913             pVideoBlock = (OMX_VIDEO_PARAM_VBSMCTYPE*) ComponentParameterStructure;
3914             if (pVideoBlock->nPortIndex != iCompressedFormatPortNum)
3915             {
3916                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3917                 return OMX_ErrorBadPortIndex;
3918             }
3919             PortIndex = pVideoBlock->nPortIndex;
3920             oscl_memcpy(pVideoBlock, &ipPorts[PortIndex]->VideoBlockMotionSize, sizeof(OMX_VIDEO_PARAM_VBSMCTYPE));
3921             SetHeader(pVideoBlock, sizeof(OMX_VIDEO_PARAM_VBSMCTYPE));
3922         }
3923         break;
3924 
3925         case OMX_IndexParamVideoMotionVector:
3926         {
3927             pVideoMotionVector = (OMX_VIDEO_PARAM_MOTIONVECTORTYPE*) ComponentParameterStructure;
3928             if (pVideoMotionVector->nPortIndex != iCompressedFormatPortNum)
3929             {
3930                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3931                 return OMX_ErrorBadPortIndex;
3932             }
3933             PortIndex = pVideoMotionVector->nPortIndex;
3934             oscl_memcpy(pVideoMotionVector, &ipPorts[PortIndex]->VideoMotionVector, sizeof(OMX_VIDEO_PARAM_MOTIONVECTORTYPE));
3935             SetHeader(pVideoMotionVector, sizeof(OMX_VIDEO_PARAM_MOTIONVECTORTYPE));
3936         }
3937         break;
3938 
3939         case OMX_IndexParamVideoIntraRefresh:
3940         {
3941             pVideoIntraRefresh = (OMX_VIDEO_PARAM_INTRAREFRESHTYPE*) ComponentParameterStructure;
3942             if (pVideoIntraRefresh->nPortIndex != iCompressedFormatPortNum)
3943             {
3944                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error bad port index"));
3945                 return OMX_ErrorBadPortIndex;
3946             }
3947             PortIndex = pVideoIntraRefresh->nPortIndex;
3948             oscl_memcpy(pVideoIntraRefresh, &ipPorts[PortIndex]->VideoIntraRefresh, sizeof(OMX_VIDEO_PARAM_INTRAREFRESHTYPE));
3949             SetHeader(pVideoIntraRefresh, sizeof(OMX_VIDEO_PARAM_INTRAREFRESHTYPE));
3950         }
3951         break;
3952 
3953         default:
3954         {
3955             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter error Unsupported Index"));
3956             return OMX_ErrorUnsupportedIndex;
3957         }
3958         // break;   This break statement was removed to avoid compiler warning for Unreachable Code
3959     }
3960 
3961     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : GetParameter OUT"));
3962 
3963     return OMX_ErrorNone;
3964 
3965 }
3966 
3967 
SetParameter(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nParamIndex,OMX_IN OMX_PTR ComponentParameterStructure)3968 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentVideo::SetParameter(
3969     OMX_IN  OMX_HANDLETYPE hComponent,
3970     OMX_IN  OMX_INDEXTYPE nParamIndex,
3971     OMX_IN  OMX_PTR ComponentParameterStructure)
3972 {
3973     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter IN"));
3974 
3975     OMX_ERRORTYPE ErrorType = OMX_ErrorNone;
3976     OMX_PRIORITYMGMTTYPE* pPrioMgmt;
3977     OMX_VIDEO_PARAM_PORTFORMATTYPE* pVideoPortFormat;
3978     OMX_VIDEO_PARAM_PROFILELEVELTYPE* pProfileLevel;
3979     OMX_PARAM_BUFFERSUPPLIERTYPE* pBufSupply;
3980     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef ;
3981     OMX_U32 PortIndex;
3982 
3983     OMX_PARAM_COMPONENTROLETYPE* pCompRole;
3984     OMX_VIDEO_PARAM_MPEG4TYPE*   pVideoMpeg4;
3985     OMX_VIDEO_PARAM_H263TYPE*    pVideoH263;
3986     OMX_VIDEO_PARAM_WMVTYPE*     pVideoWmv;
3987     OMX_VIDEO_PARAM_AVCTYPE*     pVideoAvc;
3988 
3989     //Video encoder configuration parameters
3990     OMX_CONFIG_ROTATIONTYPE*             pVideoRotation;
3991     OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* pVideoErrCorr;
3992     OMX_VIDEO_PARAM_BITRATETYPE*         pVideoRateControl;
3993     OMX_VIDEO_PARAM_QUANTIZATIONTYPE*    pVideoQuant;
3994     OMX_VIDEO_PARAM_VBSMCTYPE*           pVideoBlock;
3995     OMX_VIDEO_PARAM_MOTIONVECTORTYPE*    pVideoMotionVector;
3996     OMX_VIDEO_PARAM_INTRAREFRESHTYPE*    pVideoIntraRefresh;
3997 
3998 
3999     ComponentPortType* pComponentPort;
4000 
4001     if (NULL == ComponentParameterStructure)
4002     {
4003         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error bad parameter"));
4004         return OMX_ErrorBadParameter;
4005     }
4006 
4007     switch (nParamIndex)
4008     {
4009         case OMX_IndexParamVideoInit:
4010         {
4011             /*Check Structure Header*/
4012             CheckHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE));
4013             if (ErrorType != OMX_ErrorNone)
4014             {
4015                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error video init check header failed"));
4016                 return ErrorType;
4017             }
4018             oscl_memcpy(&iPortTypesParam, ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE));
4019         }
4020         break;
4021 
4022         case OMX_IndexParamVideoPortFormat:
4023         {
4024             pVideoPortFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE*) ComponentParameterStructure;
4025             PortIndex = pVideoPortFormat->nPortIndex;
4026             /*Check Structure Header and verify component state*/
4027             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pVideoPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
4028             if (ErrorType != OMX_ErrorNone)
4029             {
4030                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error parameter sanity check error"));
4031                 return ErrorType;
4032             }
4033             if (PortIndex <= 1)
4034             {
4035                 pComponentPort = (ComponentPortType*) ipPorts[PortIndex];
4036                 oscl_memcpy(&pComponentPort->VideoParam, pVideoPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
4037             }
4038             else
4039             {
4040                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error bad port index"));
4041                 return OMX_ErrorBadPortIndex;
4042             }
4043         }
4044         break;
4045 
4046         case OMX_IndexParamVideoMpeg4:
4047         {
4048             pVideoMpeg4 = (OMX_VIDEO_PARAM_MPEG4TYPE*) ComponentParameterStructure;
4049             PortIndex = pVideoMpeg4->nPortIndex;
4050             /*Check Structure Header and verify component state*/
4051             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pVideoMpeg4, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
4052             if (ErrorType != OMX_ErrorNone)
4053             {
4054                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error param check failed"));
4055                 return ErrorType;
4056             }
4057             oscl_memcpy(&ipPorts[PortIndex]->VideoMpeg4, pVideoMpeg4, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
4058         }
4059         break;
4060 
4061         case OMX_IndexParamVideoH263:
4062         {
4063             pVideoH263 = (OMX_VIDEO_PARAM_H263TYPE*) ComponentParameterStructure;
4064             PortIndex = pVideoH263->nPortIndex;
4065             /*Check Structure Header and verify component state*/
4066             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pVideoH263, sizeof(OMX_VIDEO_PARAM_H263TYPE));
4067             if (ErrorType != OMX_ErrorNone)
4068             {
4069                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error param check failed"));
4070                 return ErrorType;
4071             }
4072             oscl_memcpy(&ipPorts[PortIndex]->VideoH263, pVideoH263, sizeof(OMX_VIDEO_PARAM_H263TYPE));
4073         }
4074         break;
4075 
4076         case OMX_IndexParamVideoAvc:
4077         {
4078             pVideoAvc = (OMX_VIDEO_PARAM_AVCTYPE*) ComponentParameterStructure;
4079             PortIndex = pVideoAvc->nPortIndex;
4080             /*Check Structure Header and verify component state*/
4081             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pVideoAvc, sizeof(OMX_VIDEO_PARAM_AVCTYPE));
4082             if (ErrorType != OMX_ErrorNone)
4083             {
4084                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error parameter sanity check error"));
4085                 return ErrorType;
4086             }
4087             oscl_memcpy(&ipPorts[PortIndex]->VideoAvc, pVideoAvc, sizeof(OMX_VIDEO_PARAM_AVCTYPE));
4088         }
4089         break;
4090 
4091         case OMX_IndexParamVideoWmv:
4092         {
4093             pVideoWmv = (OMX_VIDEO_PARAM_WMVTYPE*)ComponentParameterStructure;
4094             PortIndex = pVideoWmv->nPortIndex;
4095             /*Check Structure Header and verify component state*/
4096             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pVideoWmv, sizeof(OMX_VIDEO_PARAM_WMVTYPE));
4097             if (ErrorType != OMX_ErrorNone)
4098             {
4099                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error param check failed"));
4100                 return ErrorType;
4101             }
4102             oscl_memcpy(&ipPorts[PortIndex]->VideoWmv, pVideoWmv, sizeof(OMX_VIDEO_PARAM_WMVTYPE));
4103         }
4104         break;
4105 
4106 
4107         case OMX_IndexParamVideoProfileLevelCurrent:
4108         {
4109             pProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*) ComponentParameterStructure;
4110             PortIndex = pProfileLevel->nPortIndex;
4111             /*Check Structure Header and verify component state*/
4112             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE));
4113             if (OMX_ErrorNone != ErrorType)
4114             {
4115                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error parameter sanity check error"));
4116                 return ErrorType;
4117             }
4118             oscl_memcpy(&ipPorts[PortIndex]->ProfileLevel, pProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE));
4119         }
4120         break;
4121 
4122         case OMX_IndexParamPriorityMgmt:
4123         {
4124             if (iState != OMX_StateLoaded && iState != OMX_StateWaitForResources)
4125             {
4126                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error incorrect state error"));
4127                 return OMX_ErrorIncorrectStateOperation;
4128             }
4129             pPrioMgmt = (OMX_PRIORITYMGMTTYPE*) ComponentParameterStructure;
4130             if ((ErrorType = CheckHeader(pPrioMgmt, sizeof(OMX_PRIORITYMGMTTYPE))) != OMX_ErrorNone)
4131             {
4132                 break;
4133             }
4134             iGroupPriority = pPrioMgmt->nGroupPriority;
4135             iGroupID = pPrioMgmt->nGroupID;
4136         }
4137         break;
4138 
4139         case OMX_IndexParamPortDefinition:
4140         {
4141             pPortDef  = (OMX_PARAM_PORTDEFINITIONTYPE*) ComponentParameterStructure;
4142             PortIndex = pPortDef->nPortIndex;
4143 
4144             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
4145             if (ErrorType != OMX_ErrorNone)
4146             {
4147                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error parameter sanity check error"));
4148                 return ErrorType;
4149             }
4150 
4151             ipPorts[PortIndex]->PortParam.nBufferCountActual = pPortDef->nBufferCountActual;
4152             ipPorts[PortIndex]->PortParam.nBufferSize = pPortDef->nBufferSize;
4153 
4154             oscl_memcpy(&ipPorts[PortIndex]->PortParam.format.video, &pPortDef->format.video, sizeof(OMX_VIDEO_PORTDEFINITIONTYPE));
4155 
4156         }
4157         break;
4158 
4159         case OMX_IndexParamCompBufferSupplier:
4160         {
4161             pBufSupply = (OMX_PARAM_BUFFERSUPPLIERTYPE*) ComponentParameterStructure;
4162             PortIndex = pBufSupply->nPortIndex;
4163 
4164             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pBufSupply, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
4165             if (OMX_ErrorIncorrectStateOperation == ErrorType)
4166             {
4167                 if (PORT_IS_ENABLED(ipPorts[pBufSupply->nPortIndex]))
4168                 {
4169                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error incorrect state error"));
4170                     return OMX_ErrorIncorrectStateOperation;
4171                 }
4172             }
4173             else if (ErrorType != OMX_ErrorNone)
4174             {
4175                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error parameter sanity check error"));
4176                 return ErrorType;
4177             }
4178 
4179             if (pBufSupply->eBufferSupplier == OMX_BufferSupplyUnspecified)
4180             {
4181                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter OUT"));
4182                 return OMX_ErrorNone;
4183             }
4184 
4185             ErrorType = OMX_ErrorNone;
4186         }
4187         break;
4188 
4189         case OMX_IndexParamStandardComponentRole:
4190         {
4191             pCompRole = (OMX_PARAM_COMPONENTROLETYPE*) ComponentParameterStructure;
4192             if ((ErrorType = CheckHeader(pCompRole, sizeof(OMX_PARAM_COMPONENTROLETYPE))) != OMX_ErrorNone)
4193             {
4194                 break;
4195             }
4196             oscl_strncpy((OMX_STRING)iComponentRole, (OMX_STRING)pCompRole->cRole, OMX_MAX_STRINGNAME_SIZE);
4197             iComponentRoleFlag = OMX_TRUE;
4198         }
4199         break;
4200 
4201 
4202         case OMX_IndexConfigCommonRotate:
4203         {
4204             pVideoRotation = (OMX_CONFIG_ROTATIONTYPE*) ComponentParameterStructure;
4205             PortIndex = pVideoRotation->nPortIndex;
4206             /*Check Structure Header and verify component state*/
4207             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pVideoRotation, sizeof(OMX_CONFIG_ROTATIONTYPE));
4208             if (ErrorType != OMX_ErrorNone)
4209             {
4210                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error param check failed"));
4211                 return ErrorType;
4212             }
4213             oscl_memcpy(&ipPorts[PortIndex]->VideoOrientationType, pVideoRotation, sizeof(OMX_CONFIG_ROTATIONTYPE));
4214         }
4215         break;
4216 
4217         case OMX_IndexParamVideoErrorCorrection:
4218         {
4219             pVideoErrCorr = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE*) ComponentParameterStructure;
4220             PortIndex = pVideoErrCorr->nPortIndex;
4221             /*Check Structure Header and verify component state*/
4222             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pVideoErrCorr, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));
4223             if (ErrorType != OMX_ErrorNone)
4224             {
4225                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error param check failed"));
4226                 return ErrorType;
4227             }
4228             oscl_memcpy(&ipPorts[PortIndex]->VideoErrorCorrection, pVideoErrCorr, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));
4229         }
4230         break;
4231 
4232         case OMX_IndexParamVideoBitrate:
4233         {
4234             pVideoRateControl = (OMX_VIDEO_PARAM_BITRATETYPE*) ComponentParameterStructure;
4235             PortIndex = pVideoRateControl->nPortIndex;
4236             /*Check Structure Header and verify component state*/
4237             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pVideoRateControl, sizeof(OMX_VIDEO_PARAM_BITRATETYPE));
4238             if (ErrorType != OMX_ErrorNone)
4239             {
4240                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error param check failed"));
4241                 return ErrorType;
4242             }
4243             oscl_memcpy(&ipPorts[PortIndex]->VideoRateType, pVideoRateControl, sizeof(OMX_VIDEO_PARAM_BITRATETYPE));
4244         }
4245         break;
4246 
4247         case OMX_IndexParamVideoQuantization:
4248         {
4249             pVideoQuant = (OMX_VIDEO_PARAM_QUANTIZATIONTYPE*) ComponentParameterStructure;
4250             PortIndex = pVideoQuant->nPortIndex;
4251             /*Check Structure Header and verify component state*/
4252             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pVideoQuant, sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE));
4253             if (ErrorType != OMX_ErrorNone)
4254             {
4255                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error param check failed"));
4256                 return ErrorType;
4257             }
4258             oscl_memcpy(&ipPorts[PortIndex]->VideoQuantType, pVideoQuant, sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE));
4259         }
4260         break;
4261 
4262         case OMX_IndexParamVideoVBSMC:
4263         {
4264             pVideoBlock = (OMX_VIDEO_PARAM_VBSMCTYPE*) ComponentParameterStructure;
4265             PortIndex = pVideoBlock->nPortIndex;
4266             /*Check Structure Header and verify component state*/
4267             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pVideoBlock, sizeof(OMX_VIDEO_PARAM_VBSMCTYPE));
4268             if (ErrorType != OMX_ErrorNone)
4269             {
4270                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error param check failed"));
4271                 return ErrorType;
4272             }
4273             oscl_memcpy(&ipPorts[PortIndex]->VideoBlockMotionSize, pVideoBlock, sizeof(OMX_VIDEO_PARAM_VBSMCTYPE));
4274         }
4275         break;
4276 
4277         case OMX_IndexParamVideoMotionVector:
4278         {
4279             pVideoMotionVector = (OMX_VIDEO_PARAM_MOTIONVECTORTYPE*) ComponentParameterStructure;
4280             PortIndex = pVideoMotionVector->nPortIndex;
4281             /*Check Structure Header and verify component state*/
4282             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pVideoMotionVector, sizeof(OMX_VIDEO_PARAM_MOTIONVECTORTYPE));
4283             if (ErrorType != OMX_ErrorNone)
4284             {
4285                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error param check failed"));
4286                 return ErrorType;
4287             }
4288             oscl_memcpy(&ipPorts[PortIndex]->VideoMotionVector, pVideoMotionVector, sizeof(OMX_VIDEO_PARAM_MOTIONVECTORTYPE));
4289         }
4290         break;
4291 
4292         case OMX_IndexParamVideoIntraRefresh:
4293         {
4294             pVideoIntraRefresh = (OMX_VIDEO_PARAM_INTRAREFRESHTYPE*) ComponentParameterStructure;
4295             PortIndex = pVideoIntraRefresh->nPortIndex;
4296             /*Check Structure Header and verify component state*/
4297             ErrorType = ParameterSanityCheck(hComponent, PortIndex, pVideoIntraRefresh, sizeof(OMX_VIDEO_PARAM_INTRAREFRESHTYPE));
4298             if (ErrorType != OMX_ErrorNone)
4299             {
4300                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error param check failed"));
4301                 return ErrorType;
4302             }
4303             oscl_memcpy(&ipPorts[PortIndex]->VideoIntraRefresh, pVideoIntraRefresh, sizeof(OMX_VIDEO_PARAM_INTRAREFRESHTYPE));
4304         }
4305         break;
4306 
4307 
4308         default:
4309         {
4310             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter error Unsupported index"));
4311             return OMX_ErrorUnsupportedIndex;
4312         }
4313         // break;   This break statement was removed to avoid compiler warning for Unreachable Code
4314     }
4315 
4316     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "OmxComponentVideo : SetParameter OUT"));
4317     return ErrorType;
4318 
4319 }
4320 #if PROXY_INTERFACE
4321 
4322 /** Component entry points declarations with proxy interface*/
BaseComponentProxyGetConfig(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nIndex,OMX_INOUT OMX_PTR pComponentConfigStructure)4323 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentProxyGetConfig(
4324     OMX_IN  OMX_HANDLETYPE hComponent,
4325     OMX_IN  OMX_INDEXTYPE nIndex,
4326     OMX_INOUT OMX_PTR pComponentConfigStructure)
4327 {
4328     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
4329     if (NULL == pOpenmaxAOType)
4330     {
4331         return OMX_ErrorBadParameter;
4332     }
4333 
4334     OMX_ERRORTYPE ReturnValue;
4335 
4336     ReturnValue = ((ProxyApplication_OMX*)(pOpenmaxAOType->ipComponentProxy))->ProxyGetConfig(hComponent, nIndex, pComponentConfigStructure);
4337     return ReturnValue;
4338 }
4339 
BaseComponentProxySetConfig(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nIndex,OMX_IN OMX_PTR pComponentConfigStructure)4340 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentProxySetConfig(
4341     OMX_IN  OMX_HANDLETYPE hComponent,
4342     OMX_IN  OMX_INDEXTYPE nIndex,
4343     OMX_IN  OMX_PTR pComponentConfigStructure)
4344 {
4345     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
4346     if (NULL == pOpenmaxAOType)
4347     {
4348         return OMX_ErrorBadParameter;
4349     }
4350 
4351     OMX_ERRORTYPE ReturnValue;
4352 
4353     ReturnValue = ((ProxyApplication_OMX*)(pOpenmaxAOType->ipComponentProxy))->ProxySetConfig(hComponent, nIndex, pComponentConfigStructure);
4354     return ReturnValue;
4355 }
4356 
BaseComponentProxyGetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_STRING cParameterName,OMX_OUT OMX_INDEXTYPE * pIndexType)4357 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentProxyGetExtensionIndex(
4358     OMX_IN  OMX_HANDLETYPE hComponent,
4359     OMX_IN  OMX_STRING cParameterName,
4360     OMX_OUT OMX_INDEXTYPE* pIndexType)
4361 {
4362     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
4363     if (NULL == pOpenmaxAOType)
4364     {
4365         return OMX_ErrorBadParameter;
4366     }
4367 
4368     OMX_ERRORTYPE ReturnValue;
4369 
4370     ReturnValue = ((ProxyApplication_OMX*)(pOpenmaxAOType->ipComponentProxy))->ProxyGetExtensionIndex(hComponent, cParameterName, pIndexType);
4371     return ReturnValue;
4372 }
4373 
BaseComponentProxyGetState(OMX_IN OMX_HANDLETYPE hComponent,OMX_OUT OMX_STATETYPE * pState)4374 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentProxyGetState(
4375     OMX_IN  OMX_HANDLETYPE hComponent,
4376     OMX_OUT OMX_STATETYPE* pState)
4377 {
4378     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
4379     if (NULL == pOpenmaxAOType)
4380     {
4381         return OMX_ErrorBadParameter;
4382     }
4383 
4384     OMX_ERRORTYPE ReturnValue;
4385 
4386     ReturnValue = ((ProxyApplication_OMX*)(pOpenmaxAOType->ipComponentProxy))->ProxyGetState(hComponent, pState);
4387     return ReturnValue;
4388 }
4389 
4390 
BaseComponentProxyGetParameter(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nParamIndex,OMX_INOUT OMX_PTR ComponentParameterStructure)4391 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentProxyGetParameter(
4392     OMX_IN  OMX_HANDLETYPE hComponent,
4393     OMX_IN  OMX_INDEXTYPE nParamIndex,
4394     OMX_INOUT OMX_PTR ComponentParameterStructure)
4395 {
4396     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
4397     if (NULL == pOpenmaxAOType)
4398     {
4399         return OMX_ErrorBadParameter;
4400     }
4401 
4402     OMX_ERRORTYPE ReturnValue = OMX_ErrorNone;
4403 
4404     ReturnValue = ((ProxyApplication_OMX*)(pOpenmaxAOType->ipComponentProxy))->ProxyGetParameter(hComponent, nParamIndex, ComponentParameterStructure);
4405     return ReturnValue;
4406 }
4407 
4408 
BaseComponentProxySetParameter(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nParamIndex,OMX_IN OMX_PTR ComponentParameterStructure)4409 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentProxySetParameter(
4410     OMX_IN  OMX_HANDLETYPE hComponent,
4411     OMX_IN  OMX_INDEXTYPE nParamIndex,
4412     OMX_IN  OMX_PTR ComponentParameterStructure)
4413 {
4414     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
4415     if (NULL == pOpenmaxAOType)
4416     {
4417         return OMX_ErrorBadParameter;
4418     }
4419 
4420     OMX_ERRORTYPE ReturnValue;
4421 
4422     ReturnValue = ((ProxyApplication_OMX*)(pOpenmaxAOType->ipComponentProxy))->ProxySetParameter(hComponent, nParamIndex, ComponentParameterStructure);
4423     return ReturnValue;
4424 }
4425 
4426 
BaseComponentProxyUseBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_INOUT OMX_BUFFERHEADERTYPE ** ppBufferHdr,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_PTR pAppPrivate,OMX_IN OMX_U32 nSizeBytes,OMX_IN OMX_U8 * pBuffer)4427 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentProxyUseBuffer(
4428     OMX_IN OMX_HANDLETYPE hComponent,
4429     OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
4430     OMX_IN OMX_U32 nPortIndex,
4431     OMX_IN OMX_PTR pAppPrivate,
4432     OMX_IN OMX_U32 nSizeBytes,
4433     OMX_IN OMX_U8* pBuffer)
4434 {
4435     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
4436     if (NULL == pOpenmaxAOType)
4437     {
4438         return OMX_ErrorBadParameter;
4439     }
4440 
4441     OMX_ERRORTYPE ReturnValue;
4442 
4443     ReturnValue = ((ProxyApplication_OMX*)(pOpenmaxAOType->ipComponentProxy))->ProxyUseBuffer(hComponent, ppBufferHdr, nPortIndex, pAppPrivate, nSizeBytes, pBuffer);
4444     return ReturnValue;
4445 }
4446 
BaseComponentProxyAllocateBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_INOUT OMX_BUFFERHEADERTYPE ** pBuffer,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_PTR pAppPrivate,OMX_IN OMX_U32 nSizeBytes)4447 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentProxyAllocateBuffer(
4448     OMX_IN OMX_HANDLETYPE hComponent,
4449     OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
4450     OMX_IN OMX_U32 nPortIndex,
4451     OMX_IN OMX_PTR pAppPrivate,
4452     OMX_IN OMX_U32 nSizeBytes)
4453 {
4454     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
4455     if (NULL == pOpenmaxAOType)
4456     {
4457         return OMX_ErrorBadParameter;
4458     }
4459 
4460     OMX_ERRORTYPE ReturnValue;
4461 
4462     ReturnValue = ((ProxyApplication_OMX*)(pOpenmaxAOType->ipComponentProxy))->ProxyAllocateBuffer(hComponent, pBuffer, nPortIndex, pAppPrivate, nSizeBytes);
4463     return ReturnValue;
4464 }
4465 
BaseComponentProxyFreeBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)4466 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentProxyFreeBuffer(
4467     OMX_IN  OMX_HANDLETYPE hComponent,
4468     OMX_IN  OMX_U32 nPortIndex,
4469     OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
4470 {
4471     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
4472     if (NULL == pOpenmaxAOType)
4473     {
4474         return OMX_ErrorBadParameter;
4475     }
4476 
4477     OMX_ERRORTYPE ReturnValue;
4478 
4479     ReturnValue = ((ProxyApplication_OMX*)(pOpenmaxAOType->ipComponentProxy))->ProxyFreeBuffer(hComponent, nPortIndex, pBuffer);
4480     return ReturnValue;
4481 }
4482 
BaseComponentProxySetCallbacks(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_CALLBACKTYPE * pCallbacks,OMX_IN OMX_PTR pAppData)4483 OMX_ERRORTYPE OmxComponentBase::BaseComponentProxySetCallbacks(
4484     OMX_IN  OMX_HANDLETYPE hComponent,
4485     OMX_IN  OMX_CALLBACKTYPE* pCallbacks,
4486     OMX_IN  OMX_PTR pAppData)
4487 {
4488     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
4489     if (NULL == pOpenmaxAOType)
4490     {
4491         return OMX_ErrorBadParameter;
4492     }
4493 
4494     OMX_ERRORTYPE ReturnValue;
4495 
4496     ReturnValue = ((ProxyApplication_OMX*)(pOpenmaxAOType->ipComponentProxy))->ProxySetCallbacks(hComponent, pCallbacks, pAppData);
4497     return ReturnValue;
4498 }
4499 
BaseComponentProxySendCommand(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_COMMANDTYPE Cmd,OMX_IN OMX_U32 nParam,OMX_IN OMX_PTR pCmdData)4500 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentProxySendCommand(
4501     OMX_IN  OMX_HANDLETYPE hComponent,
4502     OMX_IN  OMX_COMMANDTYPE Cmd,
4503     OMX_IN  OMX_U32 nParam,
4504     OMX_IN  OMX_PTR pCmdData)
4505 {
4506     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
4507     if (NULL == pOpenmaxAOType)
4508     {
4509         return OMX_ErrorBadParameter;
4510     }
4511 
4512     OMX_ERRORTYPE ReturnValue;
4513 
4514     ReturnValue = ((ProxyApplication_OMX*)(pOpenmaxAOType->ipComponentProxy))->ProxySendCommand(hComponent, Cmd, nParam, pCmdData);
4515     return ReturnValue;
4516 }
4517 
BaseComponentProxyEmptyThisBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)4518 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentProxyEmptyThisBuffer(
4519     OMX_IN  OMX_HANDLETYPE hComponent,
4520     OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
4521 {
4522     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
4523     if (NULL == pOpenmaxAOType)
4524     {
4525         return OMX_ErrorBadParameter;
4526     }
4527 
4528     OMX_ERRORTYPE ReturnValue;
4529 
4530     ReturnValue = ((ProxyApplication_OMX*)(pOpenmaxAOType->ipComponentProxy))->ProxyEmptyThisBuffer(hComponent, pBuffer);
4531     return ReturnValue;
4532 }
4533 
4534 
BaseComponentProxyFillThisBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)4535 OSCL_EXPORT_REF OMX_ERRORTYPE OmxComponentBase::BaseComponentProxyFillThisBuffer(
4536     OMX_IN  OMX_HANDLETYPE hComponent,
4537     OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
4538 {
4539     OmxComponentBase* pOpenmaxAOType = (OmxComponentBase*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
4540     if (NULL == pOpenmaxAOType)
4541     {
4542         return OMX_ErrorBadParameter;
4543     }
4544 
4545     OMX_ERRORTYPE ReturnValue;
4546 
4547     ReturnValue = ((ProxyApplication_OMX*)(pOpenmaxAOType->ipComponentProxy))->ProxyFillThisBuffer(hComponent, pBuffer);
4548     return ReturnValue;
4549 }
4550 
4551 #endif // PROXY_INTERFACE
4552