componentbase.cpp revision 5ab694059dd6abe79303fdf2712a974d9d2e29d4
1/*
2 * Copyright (C) 2009 Wind River Systems.
3 */
4
5#include <stdlib.h>
6#include <string.h>
7
8#include <pthread.h>
9
10#include <OMX_Core.h>
11#include <OMX_Component.h>
12
13#include <componentbase.h>
14
15#include <queue.h>
16#include <workqueue.h>
17
18#define LOG_TAG "componentbase"
19#include <log.h>
20
21/*
22 * CmdProcessWork
23 */
24CmdProcessWork::CmdProcessWork(CmdHandlerInterface *ci)
25{
26    this->ci = ci;
27
28    workq = new WorkQueue;
29
30    __queue_init(&q);
31    pthread_mutex_init(&lock, NULL);
32}
33
34CmdProcessWork::~CmdProcessWork()
35{
36    workq->FlushWork();
37    delete workq;
38
39    pthread_mutex_lock(&lock);
40    queue_free_all(&q);
41    pthread_mutex_unlock(&lock);
42
43    pthread_mutex_destroy(&lock);
44}
45
46OMX_ERRORTYPE CmdProcessWork::PushCmdQueue(struct cmd_s *cmd)
47{
48    int ret;
49
50    pthread_mutex_lock(&lock);
51    ret = queue_push_tail(&q, cmd);
52    if (ret) {
53        pthread_mutex_unlock(&lock);
54        return OMX_ErrorInsufficientResources;
55    }
56
57    workq->ScheduleWork(this);
58    pthread_mutex_unlock(&lock);
59
60    return OMX_ErrorNone;
61}
62
63struct cmd_s *CmdProcessWork::PopCmdQueue(void)
64{
65    struct cmd_s *cmd;
66
67    pthread_mutex_lock(&lock);
68    cmd = (struct cmd_s *)queue_pop_head(&q);
69    pthread_mutex_unlock(&lock);
70
71    return cmd;
72}
73
74void CmdProcessWork::ScheduleIfAvailable(void)
75{
76    bool avail;
77
78    pthread_mutex_lock(&lock);
79    avail = queue_length(&q) ? true : false;
80    pthread_mutex_unlock(&lock);
81
82    if (avail)
83        workq->ScheduleWork(this);
84}
85
86void CmdProcessWork::Work(void)
87{
88    struct cmd_s *cmd;
89
90    cmd = PopCmdQueue();
91    if (cmd) {
92        ci->CmdHandler(cmd);
93        free(cmd);
94    }
95    ScheduleIfAvailable();
96}
97
98/* end of CmdProcessWork */
99
100/*
101 * ComponentBase
102 */
103/*
104 * constructor & destructor
105 */
106void ComponentBase::__ComponentBase(void)
107{
108    memset(name, 0, OMX_MAX_STRINGNAME_SIZE);
109    cmodule = NULL;
110    handle = NULL;
111
112    roles = NULL;
113    nr_roles = 0;
114
115    ports = NULL;
116    nr_ports = 0;
117    memset(&portparam, 0, sizeof(portparam));
118
119    cmdwork = new CmdProcessWork(this);
120}
121
122ComponentBase::ComponentBase()
123{
124    __ComponentBase();
125}
126
127ComponentBase::ComponentBase(const OMX_STRING name)
128{
129    __ComponentBase();
130    SetName(name);
131}
132
133ComponentBase::~ComponentBase()
134{
135    delete cmdwork;
136
137    if (roles) {
138        OMX_U32 i;
139
140        for (i = 0; i < nr_roles; i++)
141            free(roles[i]);
142
143        free(roles);
144    }
145}
146
147/* end of constructor & destructor */
148
149/*
150 * accessor
151 */
152/* name */
153void ComponentBase::SetName(const OMX_STRING name)
154{
155    strncpy(this->name, name, OMX_MAX_STRINGNAME_SIZE);
156    this->name[OMX_MAX_STRINGNAME_SIZE-1] = '\0';
157}
158
159const OMX_STRING ComponentBase::GetName(void)
160{
161    return name;
162}
163
164/* component module */
165void ComponentBase::SetCModule(CModule *cmodule)
166{
167    this->cmodule = cmodule;
168}
169
170CModule *ComponentBase::GetCModule(void)
171{
172    return cmodule;
173}
174
175/* end of accessor */
176
177/*
178 * core methods & helpers
179 */
180/* roles */
181OMX_ERRORTYPE ComponentBase::SetRolesOfComponent(OMX_U32 nr_roles,
182                                                 const OMX_U8 **roles)
183{
184    OMX_U32 i;
185
186    this->roles = (OMX_U8 **)malloc(sizeof(OMX_STRING) * nr_roles);
187    if (!this->roles)
188        return OMX_ErrorInsufficientResources;
189
190    for (i = 0; i < nr_roles; i++) {
191        this->roles[i] = (OMX_U8 *)malloc(OMX_MAX_STRINGNAME_SIZE);
192        if (!this->roles[i]) {
193            int j;
194
195            for (j = (int )i-1; j >= 0; j--)
196                free(this->roles[j]);
197            free(this->roles);
198
199            return OMX_ErrorInsufficientResources;
200        }
201
202        strncpy((OMX_STRING)&this->roles[i][0],
203                (const OMX_STRING)&roles[i][0],
204                OMX_MAX_STRINGNAME_SIZE);
205    }
206
207    this->nr_roles = nr_roles;
208    return OMX_ErrorNone;
209}
210
211OMX_ERRORTYPE ComponentBase::GetRolesOfComponent(OMX_U32 *nr_roles,
212                                                 OMX_U8 **roles)
213{
214    OMX_U32 i;
215    OMX_U32 this_nr_roles = this->nr_roles;
216
217    if (!roles) {
218        *nr_roles = this_nr_roles;
219        return OMX_ErrorNone;
220    }
221
222    if (!nr_roles || (*nr_roles != this_nr_roles))
223        return OMX_ErrorBadParameter;
224
225    for (i = 0; i < this_nr_roles; i++) {
226        if (!roles[i])
227            break;
228
229        if (roles && roles[i])
230            strncpy((OMX_STRING)&roles[i][0],
231                    (const OMX_STRING)&this->roles[i][0],
232                    OMX_MAX_STRINGNAME_SIZE);
233    }
234
235    if (i != this_nr_roles)
236        return OMX_ErrorBadParameter;
237
238    *nr_roles = this_nr_roles;
239    return OMX_ErrorNone;
240}
241
242bool ComponentBase::QueryHavingThisRole(const OMX_STRING role)
243{
244    OMX_U32 i;
245
246    if (!roles || !role)
247        return false;
248
249    for (i = 0; i < nr_roles; i++) {
250        if (!strcmp((OMX_STRING)&roles[i][0], role))
251            return true;
252    }
253
254    return false;
255}
256
257/* GetHandle & FreeHandle */
258OMX_ERRORTYPE ComponentBase::GetHandle(OMX_HANDLETYPE *pHandle,
259                                       OMX_PTR pAppData,
260                                       OMX_CALLBACKTYPE *pCallBacks)
261{
262    OMX_ERRORTYPE ret;
263
264    if (handle)
265        return OMX_ErrorUndefined;
266
267    handle = (OMX_COMPONENTTYPE *)calloc(1, sizeof(*handle));
268    if (!handle)
269        return OMX_ErrorInsufficientResources;
270
271    /* handle initialization */
272    SetTypeHeader(handle, sizeof(*handle));
273    handle->pComponentPrivate = static_cast<OMX_PTR>(this);
274    handle->pApplicationPrivate = pAppData;
275
276    /* virtual - see derived class */
277    ret = InitComponent();
278    if (ret != OMX_ErrorNone) {
279        LOGE("failed to %s::InitComponent(), ret = 0x%08x\n",
280             name, ret);
281        goto free_handle;
282    }
283
284    /* connect handle's functions */
285    handle->GetComponentVersion = GetComponentVersion;
286    handle->SendCommand = SendCommand;
287    handle->GetParameter = GetParameter;
288    handle->SetParameter = SetParameter;
289    handle->GetConfig = GetConfig;
290    handle->SetConfig = SetConfig;
291    handle->GetExtensionIndex = GetExtensionIndex;
292    handle->GetState = GetState;
293    handle->ComponentTunnelRequest = ComponentTunnelRequest;
294    handle->UseBuffer = UseBuffer;
295    handle->AllocateBuffer = AllocateBuffer;
296    handle->FreeBuffer = FreeBuffer;
297    handle->EmptyThisBuffer = EmptyThisBuffer;
298    handle->FillThisBuffer = FillThisBuffer;
299    handle->SetCallbacks = SetCallbacks;
300    handle->ComponentDeInit = ComponentDeInit;
301    handle->UseEGLImage = UseEGLImage;
302    handle->ComponentRoleEnum = ComponentRoleEnum;
303
304    appdata = pAppData;
305    callbacks = pCallBacks;
306    *pHandle = (OMX_HANDLETYPE *)handle;
307
308    return OMX_ErrorNone;
309
310free_handle:
311    free(this->handle);
312    this->handle = NULL;
313
314    return ret;
315}
316
317OMX_ERRORTYPE ComponentBase::FreeHandle(OMX_HANDLETYPE hComponent)
318{
319    OMX_ERRORTYPE ret;
320
321    if (hComponent != handle)
322        return OMX_ErrorBadParameter;
323
324    /* virtual - see derived class */
325    ret = ExitComponent();
326    if (ret != OMX_ErrorNone)
327        return ret;
328
329    free(handle);
330
331    appdata = NULL;
332    callbacks = NULL;
333
334    return OMX_ErrorNone;
335}
336
337/* end of core methods & helpers */
338
339/*
340 * component methods & helpers
341 */
342OMX_ERRORTYPE ComponentBase::GetComponentVersion(
343    OMX_IN  OMX_HANDLETYPE hComponent,
344    OMX_OUT OMX_STRING pComponentName,
345    OMX_OUT OMX_VERSIONTYPE* pComponentVersion,
346    OMX_OUT OMX_VERSIONTYPE* pSpecVersion,
347    OMX_OUT OMX_UUIDTYPE* pComponentUUID)
348{
349    ComponentBase *cbase;
350
351    if (!hComponent)
352        return OMX_ErrorBadParameter;
353
354    cbase = static_cast<ComponentBase *>
355        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
356    if (!cbase)
357        return OMX_ErrorBadParameter;
358
359    return cbase->CBaseGetComponentVersion(hComponent,
360                                           pComponentName,
361                                           pComponentVersion,
362                                           pSpecVersion,
363                                           pComponentUUID);
364}
365
366OMX_ERRORTYPE ComponentBase::CBaseGetComponentVersion(
367    OMX_IN  OMX_HANDLETYPE hComponent,
368    OMX_OUT OMX_STRING pComponentName,
369    OMX_OUT OMX_VERSIONTYPE* pComponentVersion,
370    OMX_OUT OMX_VERSIONTYPE* pSpecVersion,
371    OMX_OUT OMX_UUIDTYPE* pComponentUUID)
372{
373    /*
374     * Todo
375     */
376
377    return OMX_ErrorNotImplemented;
378}
379
380OMX_ERRORTYPE ComponentBase::SendCommand(
381    OMX_IN  OMX_HANDLETYPE hComponent,
382    OMX_IN  OMX_COMMANDTYPE Cmd,
383    OMX_IN  OMX_U32 nParam1,
384    OMX_IN  OMX_PTR pCmdData)
385{
386    ComponentBase *cbase;
387
388    if (!hComponent)
389        return OMX_ErrorBadParameter;
390
391    cbase = static_cast<ComponentBase *>
392        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
393    if (!cbase)
394        return OMX_ErrorBadParameter;
395
396    return cbase->CBaseSendCommand(hComponent, Cmd, nParam1, pCmdData);
397}
398
399OMX_ERRORTYPE ComponentBase::CBaseSendCommand(
400    OMX_IN  OMX_HANDLETYPE hComponent,
401    OMX_IN  OMX_COMMANDTYPE Cmd,
402    OMX_IN  OMX_U32 nParam1,
403    OMX_IN  OMX_PTR pCmdData)
404{
405    struct cmd_s *cmd;
406
407    if (hComponent != handle)
408        return OMX_ErrorInvalidComponent;
409
410    /* basic error check */
411    switch (Cmd) {
412    case OMX_CommandStateSet:
413        /*
414         * Todo
415         */
416        break;
417    case OMX_CommandFlush:
418        /*
419         * Todo
420         */
421        break;
422    case OMX_CommandPortDisable:
423        /*
424         * Todo
425         */
426        break;
427    case OMX_CommandPortEnable:
428        /*
429         * Todo
430         */
431        break;
432    case OMX_CommandMarkBuffer:
433        /*
434         * Todo
435         */
436        break;
437    default:
438        LOGE("command %d not supported\n", Cmd);
439        return OMX_ErrorUnsupportedIndex;
440    }
441
442    cmd = (struct cmd_s *)malloc(sizeof(*cmd));
443    if (!cmd)
444        return OMX_ErrorInsufficientResources;
445
446    cmd->cmd = Cmd;
447    cmd->param1 = nParam1;
448    cmd->cmddata = pCmdData;
449
450    return cmdwork->PushCmdQueue(cmd);
451}
452
453OMX_ERRORTYPE ComponentBase::GetParameter(
454    OMX_IN  OMX_HANDLETYPE hComponent,
455    OMX_IN  OMX_INDEXTYPE nParamIndex,
456    OMX_INOUT OMX_PTR pComponentParameterStructure)
457{
458    ComponentBase *cbase;
459
460    if (!hComponent)
461        return OMX_ErrorBadParameter;
462
463    cbase = static_cast<ComponentBase *>
464        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
465    if (!cbase)
466        return OMX_ErrorBadParameter;
467
468    return cbase->CBaseGetParameter(hComponent, nParamIndex,
469                                    pComponentParameterStructure);
470}
471
472OMX_ERRORTYPE ComponentBase::CBaseGetParameter(
473    OMX_IN  OMX_HANDLETYPE hComponent,
474    OMX_IN  OMX_INDEXTYPE nParamIndex,
475    OMX_INOUT OMX_PTR pComponentParameterStructure)
476{
477    /*
478     * Todo
479     */
480
481    return OMX_ErrorNotImplemented;
482}
483
484OMX_ERRORTYPE ComponentBase::SetParameter(
485    OMX_IN  OMX_HANDLETYPE hComponent,
486    OMX_IN  OMX_INDEXTYPE nIndex,
487    OMX_IN  OMX_PTR pComponentParameterStructure)
488{
489    ComponentBase *cbase;
490
491    if (!hComponent)
492        return OMX_ErrorBadParameter;
493
494    cbase = static_cast<ComponentBase *>
495        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
496    if (!cbase)
497        return OMX_ErrorBadParameter;
498
499    return cbase->CBaseSetParameter(hComponent, nIndex,
500                                    pComponentParameterStructure);
501}
502
503OMX_ERRORTYPE ComponentBase::CBaseSetParameter(
504    OMX_IN  OMX_HANDLETYPE hComponent,
505    OMX_IN  OMX_INDEXTYPE nIndex,
506    OMX_IN  OMX_PTR pComponentParameterStructure)
507{
508    /*
509     * Todo
510     */
511
512    return OMX_ErrorNotImplemented;
513}
514
515OMX_ERRORTYPE ComponentBase::GetConfig(
516    OMX_IN  OMX_HANDLETYPE hComponent,
517    OMX_IN  OMX_INDEXTYPE nIndex,
518    OMX_INOUT OMX_PTR pComponentConfigStructure)
519{
520    ComponentBase *cbase;
521
522    if (!hComponent)
523        return OMX_ErrorBadParameter;
524
525    cbase = static_cast<ComponentBase *>
526        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
527    if (!cbase)
528        return OMX_ErrorBadParameter;
529
530    return cbase->CBaseGetConfig(hComponent, nIndex,
531                                 pComponentConfigStructure);
532}
533
534OMX_ERRORTYPE ComponentBase::CBaseGetConfig(
535    OMX_IN  OMX_HANDLETYPE hComponent,
536    OMX_IN  OMX_INDEXTYPE nIndex,
537    OMX_INOUT OMX_PTR pComponentConfigStructure)
538{
539    /*
540     * Todo
541     */
542
543    return OMX_ErrorNotImplemented;
544}
545
546OMX_ERRORTYPE ComponentBase::SetConfig(
547    OMX_IN  OMX_HANDLETYPE hComponent,
548    OMX_IN  OMX_INDEXTYPE nIndex,
549    OMX_IN  OMX_PTR pComponentConfigStructure)
550{
551    ComponentBase *cbase;
552
553    if (!hComponent)
554        return OMX_ErrorBadParameter;
555
556    cbase = static_cast<ComponentBase *>
557        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
558    if (!cbase)
559        return OMX_ErrorBadParameter;
560
561    return cbase->CBaseSetConfig(hComponent, nIndex,
562                                 pComponentConfigStructure);
563}
564
565OMX_ERRORTYPE ComponentBase::CBaseSetConfig(
566    OMX_IN  OMX_HANDLETYPE hComponent,
567    OMX_IN  OMX_INDEXTYPE nIndex,
568    OMX_IN  OMX_PTR pComponentConfigStructure)
569{
570    /*
571     * Todo
572     */
573
574    return OMX_ErrorNotImplemented;
575}
576
577OMX_ERRORTYPE ComponentBase::GetExtensionIndex(
578    OMX_IN  OMX_HANDLETYPE hComponent,
579    OMX_IN  OMX_STRING cParameterName,
580    OMX_OUT OMX_INDEXTYPE* pIndexType)
581{
582    ComponentBase *cbase;
583
584    if (!hComponent)
585        return OMX_ErrorBadParameter;
586
587    cbase = static_cast<ComponentBase *>
588        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
589    if (!cbase)
590        return OMX_ErrorBadParameter;
591
592    return cbase->CBaseGetExtensionIndex(hComponent, cParameterName,
593                                         pIndexType);
594}
595
596OMX_ERRORTYPE ComponentBase::CBaseGetExtensionIndex(
597    OMX_IN  OMX_HANDLETYPE hComponent,
598    OMX_IN  OMX_STRING cParameterName,
599    OMX_OUT OMX_INDEXTYPE* pIndexType)
600{
601    /*
602     * Todo
603     */
604
605    return OMX_ErrorNotImplemented;
606}
607
608OMX_ERRORTYPE ComponentBase::GetState(
609    OMX_IN  OMX_HANDLETYPE hComponent,
610    OMX_OUT OMX_STATETYPE* pState)
611{
612    ComponentBase *cbase;
613
614    if (!hComponent)
615        return OMX_ErrorBadParameter;
616
617    cbase = static_cast<ComponentBase *>
618        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
619    if (!cbase)
620        return OMX_ErrorBadParameter;
621
622    return cbase->CBaseGetState(hComponent, pState);
623}
624
625OMX_ERRORTYPE ComponentBase::CBaseGetState(
626    OMX_IN  OMX_HANDLETYPE hComponent,
627    OMX_OUT OMX_STATETYPE* pState)
628{
629    /*
630     * Todo
631     */
632
633    return OMX_ErrorNotImplemented;
634}
635
636OMX_ERRORTYPE ComponentBase::ComponentTunnelRequest(
637    OMX_IN  OMX_HANDLETYPE hComponent,
638    OMX_IN  OMX_U32 nPort,
639    OMX_IN  OMX_HANDLETYPE hTunneledComponent,
640    OMX_IN  OMX_U32 nTunneledPort,
641    OMX_INOUT  OMX_TUNNELSETUPTYPE* pTunnelSetup)
642{
643    ComponentBase *cbase;
644
645    if (!hComponent)
646        return OMX_ErrorBadParameter;
647
648    cbase = static_cast<ComponentBase *>
649        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
650    if (!cbase)
651        return OMX_ErrorBadParameter;
652
653    return cbase->CBaseComponentTunnelRequest(hComponent, nPort,
654                                              hTunneledComponent,
655                                              nTunneledPort, pTunnelSetup);
656}
657
658OMX_ERRORTYPE ComponentBase::CBaseComponentTunnelRequest(
659    OMX_IN  OMX_HANDLETYPE hComp,
660    OMX_IN  OMX_U32 nPort,
661    OMX_IN  OMX_HANDLETYPE hTunneledComp,
662    OMX_IN  OMX_U32 nTunneledPort,
663    OMX_INOUT  OMX_TUNNELSETUPTYPE* pTunnelSetup)
664{
665    /*
666     * Todo
667     */
668
669    return OMX_ErrorNotImplemented;
670}
671
672OMX_ERRORTYPE ComponentBase::UseBuffer(
673    OMX_IN OMX_HANDLETYPE hComponent,
674    OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
675    OMX_IN OMX_U32 nPortIndex,
676    OMX_IN OMX_PTR pAppPrivate,
677    OMX_IN OMX_U32 nSizeBytes,
678    OMX_IN OMX_U8* pBuffer)
679{
680    ComponentBase *cbase;
681
682    if (!hComponent)
683        return OMX_ErrorBadParameter;
684
685    cbase = static_cast<ComponentBase *>
686        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
687    if (!cbase)
688        return OMX_ErrorBadParameter;
689
690    return cbase->CBaseUseBuffer(hComponent, ppBufferHdr, nPortIndex,
691                                 pAppPrivate, nSizeBytes, pBuffer);
692}
693
694OMX_ERRORTYPE ComponentBase::CBaseUseBuffer(
695    OMX_IN OMX_HANDLETYPE hComponent,
696    OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
697    OMX_IN OMX_U32 nPortIndex,
698    OMX_IN OMX_PTR pAppPrivate,
699    OMX_IN OMX_U32 nSizeBytes,
700    OMX_IN OMX_U8* pBuffer)
701{
702    /*
703     * Todo
704     */
705
706    return OMX_ErrorNotImplemented;
707}
708
709OMX_ERRORTYPE ComponentBase::AllocateBuffer(
710    OMX_IN OMX_HANDLETYPE hComponent,
711    OMX_INOUT OMX_BUFFERHEADERTYPE** ppBuffer,
712    OMX_IN OMX_U32 nPortIndex,
713    OMX_IN OMX_PTR pAppPrivate,
714    OMX_IN OMX_U32 nSizeBytes)
715{
716    ComponentBase *cbase;
717
718    if (!hComponent)
719        return OMX_ErrorBadParameter;
720
721    cbase = static_cast<ComponentBase *>
722        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
723    if (!cbase)
724        return OMX_ErrorBadParameter;
725
726    return cbase->CBaseAllocateBuffer(hComponent, ppBuffer, nPortIndex,
727                                      pAppPrivate, nSizeBytes);
728}
729
730OMX_ERRORTYPE ComponentBase::CBaseAllocateBuffer(
731    OMX_IN OMX_HANDLETYPE hComponent,
732    OMX_INOUT OMX_BUFFERHEADERTYPE** ppBuffer,
733    OMX_IN OMX_U32 nPortIndex,
734    OMX_IN OMX_PTR pAppPrivate,
735    OMX_IN OMX_U32 nSizeBytes)
736{
737    /*
738     * Todo
739     */
740
741    return OMX_ErrorNotImplemented;
742}
743
744OMX_ERRORTYPE ComponentBase::FreeBuffer(
745    OMX_IN  OMX_HANDLETYPE hComponent,
746    OMX_IN  OMX_U32 nPortIndex,
747    OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
748{
749    ComponentBase *cbase;
750
751    if (!hComponent)
752        return OMX_ErrorBadParameter;
753
754    cbase = static_cast<ComponentBase *>
755        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
756    if (!cbase)
757        return OMX_ErrorBadParameter;
758
759    return cbase->CBaseFreeBuffer(hComponent, nPortIndex, pBuffer);
760}
761
762OMX_ERRORTYPE ComponentBase::CBaseFreeBuffer(
763    OMX_IN  OMX_HANDLETYPE hComponent,
764    OMX_IN  OMX_U32 nPortIndex,
765    OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
766{
767    /*
768     * Todo
769     */
770
771    return OMX_ErrorNotImplemented;
772}
773
774OMX_ERRORTYPE ComponentBase::EmptyThisBuffer(
775    OMX_IN  OMX_HANDLETYPE hComponent,
776    OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
777{
778    ComponentBase *cbase;
779
780    if (!hComponent)
781        return OMX_ErrorBadParameter;
782
783    cbase = static_cast<ComponentBase *>
784        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
785    if (!cbase)
786        return OMX_ErrorBadParameter;
787
788    return cbase->CBaseEmptyThisBuffer(hComponent, pBuffer);
789}
790
791OMX_ERRORTYPE ComponentBase::CBaseEmptyThisBuffer(
792    OMX_IN  OMX_HANDLETYPE hComponent,
793    OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
794{
795    /*
796     * Todo
797     */
798
799    return OMX_ErrorNotImplemented;
800}
801
802OMX_ERRORTYPE ComponentBase::FillThisBuffer(
803    OMX_IN  OMX_HANDLETYPE hComponent,
804    OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
805{
806    ComponentBase *cbase;
807
808    if (!hComponent)
809        return OMX_ErrorBadParameter;
810
811    cbase = static_cast<ComponentBase *>
812        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
813    if (!cbase)
814        return OMX_ErrorBadParameter;
815
816    return cbase->CBaseFillThisBuffer(hComponent, pBuffer);
817}
818
819OMX_ERRORTYPE ComponentBase::CBaseFillThisBuffer(
820    OMX_IN  OMX_HANDLETYPE hComponent,
821    OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
822{
823    /*
824     * Todo
825     */
826
827    return OMX_ErrorNotImplemented;
828}
829
830OMX_ERRORTYPE ComponentBase::SetCallbacks(
831    OMX_IN  OMX_HANDLETYPE hComponent,
832    OMX_IN  OMX_CALLBACKTYPE* pCallbacks,
833    OMX_IN  OMX_PTR pAppData)
834{
835    ComponentBase *cbase;
836
837    if (!hComponent)
838        return OMX_ErrorBadParameter;
839
840    cbase = static_cast<ComponentBase *>
841        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
842    if (!cbase)
843        return OMX_ErrorBadParameter;
844
845    return cbase->CBaseSetCallbacks(hComponent, pCallbacks, pAppData);
846}
847
848OMX_ERRORTYPE ComponentBase::CBaseSetCallbacks(
849    OMX_IN  OMX_HANDLETYPE hComponent,
850    OMX_IN  OMX_CALLBACKTYPE *pCallbacks,
851    OMX_IN  OMX_PTR pAppData)
852{
853    if (hComponent != handle)
854        return OMX_ErrorBadParameter;
855
856    appdata = pAppData;
857    callbacks = pCallbacks;
858
859    return OMX_ErrorNone;
860}
861
862OMX_ERRORTYPE ComponentBase::ComponentDeInit(
863    OMX_IN  OMX_HANDLETYPE hComponent)
864{
865    ComponentBase *cbase;
866
867    if (!hComponent)
868        return OMX_ErrorBadParameter;
869
870    cbase = static_cast<ComponentBase *>
871        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
872    if (!cbase)
873        return OMX_ErrorBadParameter;
874
875    return cbase->CBaseComponentDeInit(hComponent);
876}
877
878OMX_ERRORTYPE ComponentBase::CBaseComponentDeInit(
879    OMX_IN  OMX_HANDLETYPE hComponent)
880{
881    /*
882     * Todo
883     */
884
885    return OMX_ErrorNotImplemented;
886}
887
888OMX_ERRORTYPE ComponentBase::UseEGLImage(
889    OMX_IN OMX_HANDLETYPE hComponent,
890    OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
891    OMX_IN OMX_U32 nPortIndex,
892    OMX_IN OMX_PTR pAppPrivate,
893    OMX_IN void* eglImage)
894{
895    ComponentBase *cbase;
896
897    if (!hComponent)
898        return OMX_ErrorBadParameter;
899
900    cbase = static_cast<ComponentBase *>
901        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
902    if (!cbase)
903        return OMX_ErrorBadParameter;
904
905    return cbase->CBaseUseEGLImage(hComponent, ppBufferHdr, nPortIndex,
906                                   pAppPrivate, eglImage);
907}
908
909OMX_ERRORTYPE ComponentBase::CBaseUseEGLImage(
910    OMX_IN OMX_HANDLETYPE hComponent,
911    OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
912    OMX_IN OMX_U32 nPortIndex,
913    OMX_IN OMX_PTR pAppPrivate,
914    OMX_IN void* eglImage)
915{
916    /*
917     * Todo
918     */
919
920    return OMX_ErrorNotImplemented;
921}
922
923OMX_ERRORTYPE ComponentBase::ComponentRoleEnum(
924    OMX_IN OMX_HANDLETYPE hComponent,
925    OMX_OUT OMX_U8 *cRole,
926    OMX_IN OMX_U32 nIndex)
927{
928    ComponentBase *cbase;
929
930    if (!hComponent)
931        return OMX_ErrorBadParameter;
932
933    cbase = static_cast<ComponentBase *>
934        (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate);
935    if (!cbase)
936        return OMX_ErrorBadParameter;
937
938    return cbase->CBaseComponentRoleEnum(hComponent, cRole, nIndex);
939}
940
941OMX_ERRORTYPE ComponentBase::CBaseComponentRoleEnum(
942    OMX_IN OMX_HANDLETYPE hComponent,
943    OMX_OUT OMX_U8 *cRole,
944    OMX_IN OMX_U32 nIndex)
945{
946    if (hComponent != (OMX_HANDLETYPE *)this->handle)
947        return OMX_ErrorBadParameter;
948
949    if (nIndex > nr_roles)
950        return OMX_ErrorBadParameter;
951
952    strncpy((char *)cRole, (const char *)roles[nIndex],
953            OMX_MAX_STRINGNAME_SIZE);
954    return OMX_ErrorNone;
955}
956
957/* implement CmdHandlerInterface */
958void ComponentBase::CmdHandler(struct cmd_s *cmd)
959{
960    OMX_EVENTTYPE event = OMX_EventCmdComplete;
961    OMX_U32 data1 = cmd->cmd, data2 = cmd->param1;
962    OMX_PTR eventdata = NULL;
963
964    switch (cmd->cmd) {
965    case OMX_CommandStateSet:
966        /*
967         * Todo
968         */
969        break;
970    case OMX_CommandFlush:
971        /*
972         * Todo
973         */
974        break;
975    case OMX_CommandPortDisable:
976        /*
977         * Todo
978         */
979        break;
980    case OMX_CommandPortEnable:
981        /*
982         * Todo
983         */
984        break;
985    case OMX_CommandMarkBuffer:
986        /*
987         * Todo
988         */
989        break;
990    }
991
992    callbacks->EventHandler(handle, appdata,
993                            event, data1, data2, eventdata);
994}
995
996/* end of component methods & helpers */
997
998/*
999 * omx header manipuation
1000 */
1001void ComponentBase::SetTypeHeader(OMX_PTR type, OMX_U32 size)
1002{
1003    OMX_U32 *nsize;
1004    OMX_VERSIONTYPE *nversion;
1005
1006    if (!type)
1007        return;
1008
1009    nsize = (OMX_U32 *)type;
1010    nversion = (OMX_VERSIONTYPE *)((OMX_U8 *)type + sizeof(OMX_U32));
1011
1012    *nsize = sizeof(size);
1013    nversion->nVersion = OMX_SPEC_VERSION;
1014}
1015
1016OMX_BOOL ComponentBase::CheckTypeHeader(OMX_PTR type, OMX_U32 size)
1017{
1018    OMX_U32 *nsize;
1019    OMX_VERSIONTYPE *nversion;
1020    OMX_U8 mismatch = 0;
1021
1022    if (!type)
1023        return OMX_FALSE;
1024
1025    nsize = (OMX_U32 *)type;
1026    nversion = (OMX_VERSIONTYPE *)((OMX_U8 *)type + sizeof(OMX_U32));
1027
1028    mismatch = (*nsize != sizeof(size)) ? 1 : 0;
1029    mismatch |= (nversion->nVersion != OMX_SPEC_VERSION) ? 1 : 0;
1030
1031    if (mismatch)
1032        return OMX_TRUE;
1033    else
1034        return OMX_FALSE;
1035}
1036
1037/* end of ComponentBase */
1038