componentbase.cpp revision e3be2d84503a7693ece53adbcf26ee243eea1b87
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 OMX_ERRORTYPE ret = OMX_ErrorNone; 478 479 switch (nParamIndex) { 480 case OMX_IndexParamAudioInit: 481 case OMX_IndexParamVideoInit: 482 case OMX_IndexParamImageInit: 483 case OMX_IndexParamOtherInit: { 484 OMX_PORT_PARAM_TYPE *p = 485 (OMX_PORT_PARAM_TYPE *)pComponentParameterStructure; 486 487 memcpy(p, &portparam, sizeof(*p)); 488 break; 489 } 490 case OMX_IndexParamPortDefinition: { 491 OMX_PARAM_PORTDEFINITIONTYPE *p = 492 (OMX_PARAM_PORTDEFINITIONTYPE *)pComponentParameterStructure; 493 OMX_U32 index = p->nPortIndex; 494 PortBase *port = ports[index]; 495 496 memcpy(p, port->GetPortParam(), sizeof(*p)); 497 break; 498 } 499 case OMX_IndexParamAudioPortFormat: { 500 OMX_AUDIO_PARAM_PORTFORMATTYPE *p = 501 (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pComponentParameterStructure; 502 OMX_U32 index = p->nPortIndex; 503 PortBase *port = ports[index]; 504 505 memcpy(p, port->GetAudioPortParam(), sizeof(*p)); 506 break; 507 } 508 case OMX_IndexParamCompBufferSupplier: 509 /* 510 * Todo 511 */ 512 513 ret = OMX_ErrorUnsupportedIndex; 514 break; 515 default: 516 ret = ComponentGetParameter(nParamIndex, pComponentParameterStructure); 517 } /* switch */ 518 519 return ret; 520} 521 522OMX_ERRORTYPE ComponentBase::SetParameter( 523 OMX_IN OMX_HANDLETYPE hComponent, 524 OMX_IN OMX_INDEXTYPE nIndex, 525 OMX_IN OMX_PTR pComponentParameterStructure) 526{ 527 ComponentBase *cbase; 528 529 if (!hComponent) 530 return OMX_ErrorBadParameter; 531 532 cbase = static_cast<ComponentBase *> 533 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 534 if (!cbase) 535 return OMX_ErrorBadParameter; 536 537 return cbase->CBaseSetParameter(hComponent, nIndex, 538 pComponentParameterStructure); 539} 540 541OMX_ERRORTYPE ComponentBase::CBaseSetParameter( 542 OMX_IN OMX_HANDLETYPE hComponent, 543 OMX_IN OMX_INDEXTYPE nIndex, 544 OMX_IN OMX_PTR pComponentParameterStructure) 545{ 546 OMX_ERRORTYPE ret = OMX_ErrorNone; 547 548 switch (nIndex) { 549 case OMX_IndexParamAudioInit: 550 case OMX_IndexParamVideoInit: 551 case OMX_IndexParamImageInit: 552 case OMX_IndexParamOtherInit: { 553 OMX_PORT_PARAM_TYPE *p = (OMX_PORT_PARAM_TYPE *) 554 pComponentParameterStructure; 555 556 memcpy(&portparam, p, sizeof(*p)); 557 break; 558 } 559 case OMX_IndexParamPortDefinition: { 560 OMX_PARAM_PORTDEFINITIONTYPE *p = 561 (OMX_PARAM_PORTDEFINITIONTYPE *)pComponentParameterStructure; 562 OMX_U32 index = p->nPortIndex; 563 PortBase *port = ports[index]; 564 565 port->SetPortParam(p); 566 break; 567 } 568 case OMX_IndexParamAudioPortFormat: { 569 OMX_AUDIO_PARAM_PORTFORMATTYPE *p = 570 (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pComponentParameterStructure; 571 OMX_U32 index = p->nPortIndex; 572 PortBase *port = ports[index]; 573 574 port->SetAudioPortParam(p); 575 break; 576 } 577 /* FIXME */ 578 case OMX_IndexParamCompBufferSupplier: 579 ret = OMX_ErrorUnsupportedIndex; 580 break; 581 default: 582 ret = ComponentGetParameter(nIndex, pComponentParameterStructure); 583 } /* switch */ 584 585 return ret; 586} 587 588OMX_ERRORTYPE ComponentBase::GetConfig( 589 OMX_IN OMX_HANDLETYPE hComponent, 590 OMX_IN OMX_INDEXTYPE nIndex, 591 OMX_INOUT OMX_PTR pComponentConfigStructure) 592{ 593 ComponentBase *cbase; 594 595 if (!hComponent) 596 return OMX_ErrorBadParameter; 597 598 cbase = static_cast<ComponentBase *> 599 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 600 if (!cbase) 601 return OMX_ErrorBadParameter; 602 603 return cbase->CBaseGetConfig(hComponent, nIndex, 604 pComponentConfigStructure); 605} 606 607OMX_ERRORTYPE ComponentBase::CBaseGetConfig( 608 OMX_IN OMX_HANDLETYPE hComponent, 609 OMX_IN OMX_INDEXTYPE nIndex, 610 OMX_INOUT OMX_PTR pComponentConfigStructure) 611{ 612 OMX_ERRORTYPE ret; 613 614 if (hComponent != handle) 615 return OMX_ErrorBadParameter; 616 617 switch (nIndex) { 618 default: 619 ret = ComponentGetConfig(nIndex, pComponentConfigStructure); 620 } 621 622 return ret; 623} 624 625OMX_ERRORTYPE ComponentBase::SetConfig( 626 OMX_IN OMX_HANDLETYPE hComponent, 627 OMX_IN OMX_INDEXTYPE nIndex, 628 OMX_IN OMX_PTR pComponentConfigStructure) 629{ 630 ComponentBase *cbase; 631 632 if (!hComponent) 633 return OMX_ErrorBadParameter; 634 635 cbase = static_cast<ComponentBase *> 636 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 637 if (!cbase) 638 return OMX_ErrorBadParameter; 639 640 return cbase->CBaseSetConfig(hComponent, nIndex, 641 pComponentConfigStructure); 642} 643 644OMX_ERRORTYPE ComponentBase::CBaseSetConfig( 645 OMX_IN OMX_HANDLETYPE hComponent, 646 OMX_IN OMX_INDEXTYPE nIndex, 647 OMX_IN OMX_PTR pComponentConfigStructure) 648{ 649 OMX_ERRORTYPE ret; 650 651 if (hComponent != handle) 652 return OMX_ErrorBadParameter; 653 654 switch (nIndex) { 655 default: 656 ret = ComponentSetConfig(nIndex, pComponentConfigStructure); 657 } 658 659 return ret; 660} 661 662OMX_ERRORTYPE ComponentBase::GetExtensionIndex( 663 OMX_IN OMX_HANDLETYPE hComponent, 664 OMX_IN OMX_STRING cParameterName, 665 OMX_OUT OMX_INDEXTYPE* pIndexType) 666{ 667 ComponentBase *cbase; 668 669 if (!hComponent) 670 return OMX_ErrorBadParameter; 671 672 cbase = static_cast<ComponentBase *> 673 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 674 if (!cbase) 675 return OMX_ErrorBadParameter; 676 677 return cbase->CBaseGetExtensionIndex(hComponent, cParameterName, 678 pIndexType); 679} 680 681OMX_ERRORTYPE ComponentBase::CBaseGetExtensionIndex( 682 OMX_IN OMX_HANDLETYPE hComponent, 683 OMX_IN OMX_STRING cParameterName, 684 OMX_OUT OMX_INDEXTYPE* pIndexType) 685{ 686 /* 687 * Todo 688 */ 689 690 return OMX_ErrorNotImplemented; 691} 692 693OMX_ERRORTYPE ComponentBase::GetState( 694 OMX_IN OMX_HANDLETYPE hComponent, 695 OMX_OUT OMX_STATETYPE* pState) 696{ 697 ComponentBase *cbase; 698 699 if (!hComponent) 700 return OMX_ErrorBadParameter; 701 702 cbase = static_cast<ComponentBase *> 703 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 704 if (!cbase) 705 return OMX_ErrorBadParameter; 706 707 return cbase->CBaseGetState(hComponent, pState); 708} 709 710OMX_ERRORTYPE ComponentBase::CBaseGetState( 711 OMX_IN OMX_HANDLETYPE hComponent, 712 OMX_OUT OMX_STATETYPE* pState) 713{ 714 /* 715 * Todo 716 */ 717 718 return OMX_ErrorNotImplemented; 719} 720 721OMX_ERRORTYPE ComponentBase::ComponentTunnelRequest( 722 OMX_IN OMX_HANDLETYPE hComponent, 723 OMX_IN OMX_U32 nPort, 724 OMX_IN OMX_HANDLETYPE hTunneledComponent, 725 OMX_IN OMX_U32 nTunneledPort, 726 OMX_INOUT OMX_TUNNELSETUPTYPE* pTunnelSetup) 727{ 728 ComponentBase *cbase; 729 730 if (!hComponent) 731 return OMX_ErrorBadParameter; 732 733 cbase = static_cast<ComponentBase *> 734 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 735 if (!cbase) 736 return OMX_ErrorBadParameter; 737 738 return cbase->CBaseComponentTunnelRequest(hComponent, nPort, 739 hTunneledComponent, 740 nTunneledPort, pTunnelSetup); 741} 742 743OMX_ERRORTYPE ComponentBase::CBaseComponentTunnelRequest( 744 OMX_IN OMX_HANDLETYPE hComp, 745 OMX_IN OMX_U32 nPort, 746 OMX_IN OMX_HANDLETYPE hTunneledComp, 747 OMX_IN OMX_U32 nTunneledPort, 748 OMX_INOUT OMX_TUNNELSETUPTYPE* pTunnelSetup) 749{ 750 /* 751 * Todo 752 */ 753 754 return OMX_ErrorNotImplemented; 755} 756 757OMX_ERRORTYPE ComponentBase::UseBuffer( 758 OMX_IN OMX_HANDLETYPE hComponent, 759 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 760 OMX_IN OMX_U32 nPortIndex, 761 OMX_IN OMX_PTR pAppPrivate, 762 OMX_IN OMX_U32 nSizeBytes, 763 OMX_IN OMX_U8* pBuffer) 764{ 765 ComponentBase *cbase; 766 767 if (!hComponent) 768 return OMX_ErrorBadParameter; 769 770 cbase = static_cast<ComponentBase *> 771 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 772 if (!cbase) 773 return OMX_ErrorBadParameter; 774 775 return cbase->CBaseUseBuffer(hComponent, ppBufferHdr, nPortIndex, 776 pAppPrivate, nSizeBytes, pBuffer); 777} 778 779OMX_ERRORTYPE ComponentBase::CBaseUseBuffer( 780 OMX_IN OMX_HANDLETYPE hComponent, 781 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 782 OMX_IN OMX_U32 nPortIndex, 783 OMX_IN OMX_PTR pAppPrivate, 784 OMX_IN OMX_U32 nSizeBytes, 785 OMX_IN OMX_U8* pBuffer) 786{ 787 /* 788 * Todo 789 */ 790 791 return OMX_ErrorNotImplemented; 792} 793 794OMX_ERRORTYPE ComponentBase::AllocateBuffer( 795 OMX_IN OMX_HANDLETYPE hComponent, 796 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBuffer, 797 OMX_IN OMX_U32 nPortIndex, 798 OMX_IN OMX_PTR pAppPrivate, 799 OMX_IN OMX_U32 nSizeBytes) 800{ 801 ComponentBase *cbase; 802 803 if (!hComponent) 804 return OMX_ErrorBadParameter; 805 806 cbase = static_cast<ComponentBase *> 807 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 808 if (!cbase) 809 return OMX_ErrorBadParameter; 810 811 return cbase->CBaseAllocateBuffer(hComponent, ppBuffer, nPortIndex, 812 pAppPrivate, nSizeBytes); 813} 814 815OMX_ERRORTYPE ComponentBase::CBaseAllocateBuffer( 816 OMX_IN OMX_HANDLETYPE hComponent, 817 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBuffer, 818 OMX_IN OMX_U32 nPortIndex, 819 OMX_IN OMX_PTR pAppPrivate, 820 OMX_IN OMX_U32 nSizeBytes) 821{ 822 /* 823 * Todo 824 */ 825 826 return OMX_ErrorNotImplemented; 827} 828 829OMX_ERRORTYPE ComponentBase::FreeBuffer( 830 OMX_IN OMX_HANDLETYPE hComponent, 831 OMX_IN OMX_U32 nPortIndex, 832 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 833{ 834 ComponentBase *cbase; 835 836 if (!hComponent) 837 return OMX_ErrorBadParameter; 838 839 cbase = static_cast<ComponentBase *> 840 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 841 if (!cbase) 842 return OMX_ErrorBadParameter; 843 844 return cbase->CBaseFreeBuffer(hComponent, nPortIndex, pBuffer); 845} 846 847OMX_ERRORTYPE ComponentBase::CBaseFreeBuffer( 848 OMX_IN OMX_HANDLETYPE hComponent, 849 OMX_IN OMX_U32 nPortIndex, 850 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 851{ 852 /* 853 * Todo 854 */ 855 856 return OMX_ErrorNotImplemented; 857} 858 859OMX_ERRORTYPE ComponentBase::EmptyThisBuffer( 860 OMX_IN OMX_HANDLETYPE hComponent, 861 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 862{ 863 ComponentBase *cbase; 864 865 if (!hComponent) 866 return OMX_ErrorBadParameter; 867 868 cbase = static_cast<ComponentBase *> 869 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 870 if (!cbase) 871 return OMX_ErrorBadParameter; 872 873 return cbase->CBaseEmptyThisBuffer(hComponent, pBuffer); 874} 875 876OMX_ERRORTYPE ComponentBase::CBaseEmptyThisBuffer( 877 OMX_IN OMX_HANDLETYPE hComponent, 878 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 879{ 880 /* 881 * Todo 882 */ 883 884 return OMX_ErrorNotImplemented; 885} 886 887OMX_ERRORTYPE ComponentBase::FillThisBuffer( 888 OMX_IN OMX_HANDLETYPE hComponent, 889 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 890{ 891 ComponentBase *cbase; 892 893 if (!hComponent) 894 return OMX_ErrorBadParameter; 895 896 cbase = static_cast<ComponentBase *> 897 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 898 if (!cbase) 899 return OMX_ErrorBadParameter; 900 901 return cbase->CBaseFillThisBuffer(hComponent, pBuffer); 902} 903 904OMX_ERRORTYPE ComponentBase::CBaseFillThisBuffer( 905 OMX_IN OMX_HANDLETYPE hComponent, 906 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 907{ 908 /* 909 * Todo 910 */ 911 912 return OMX_ErrorNotImplemented; 913} 914 915OMX_ERRORTYPE ComponentBase::SetCallbacks( 916 OMX_IN OMX_HANDLETYPE hComponent, 917 OMX_IN OMX_CALLBACKTYPE* pCallbacks, 918 OMX_IN OMX_PTR pAppData) 919{ 920 ComponentBase *cbase; 921 922 if (!hComponent) 923 return OMX_ErrorBadParameter; 924 925 cbase = static_cast<ComponentBase *> 926 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 927 if (!cbase) 928 return OMX_ErrorBadParameter; 929 930 return cbase->CBaseSetCallbacks(hComponent, pCallbacks, pAppData); 931} 932 933OMX_ERRORTYPE ComponentBase::CBaseSetCallbacks( 934 OMX_IN OMX_HANDLETYPE hComponent, 935 OMX_IN OMX_CALLBACKTYPE *pCallbacks, 936 OMX_IN OMX_PTR pAppData) 937{ 938 if (hComponent != handle) 939 return OMX_ErrorBadParameter; 940 941 appdata = pAppData; 942 callbacks = pCallbacks; 943 944 return OMX_ErrorNone; 945} 946 947OMX_ERRORTYPE ComponentBase::ComponentDeInit( 948 OMX_IN OMX_HANDLETYPE hComponent) 949{ 950 ComponentBase *cbase; 951 952 if (!hComponent) 953 return OMX_ErrorBadParameter; 954 955 cbase = static_cast<ComponentBase *> 956 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 957 if (!cbase) 958 return OMX_ErrorBadParameter; 959 960 return cbase->CBaseComponentDeInit(hComponent); 961} 962 963OMX_ERRORTYPE ComponentBase::CBaseComponentDeInit( 964 OMX_IN OMX_HANDLETYPE hComponent) 965{ 966 /* 967 * Todo 968 */ 969 970 return OMX_ErrorNotImplemented; 971} 972 973OMX_ERRORTYPE ComponentBase::UseEGLImage( 974 OMX_IN OMX_HANDLETYPE hComponent, 975 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 976 OMX_IN OMX_U32 nPortIndex, 977 OMX_IN OMX_PTR pAppPrivate, 978 OMX_IN void* eglImage) 979{ 980 ComponentBase *cbase; 981 982 if (!hComponent) 983 return OMX_ErrorBadParameter; 984 985 cbase = static_cast<ComponentBase *> 986 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 987 if (!cbase) 988 return OMX_ErrorBadParameter; 989 990 return cbase->CBaseUseEGLImage(hComponent, ppBufferHdr, nPortIndex, 991 pAppPrivate, eglImage); 992} 993 994OMX_ERRORTYPE ComponentBase::CBaseUseEGLImage( 995 OMX_IN OMX_HANDLETYPE hComponent, 996 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 997 OMX_IN OMX_U32 nPortIndex, 998 OMX_IN OMX_PTR pAppPrivate, 999 OMX_IN void* eglImage) 1000{ 1001 /* 1002 * Todo 1003 */ 1004 1005 return OMX_ErrorNotImplemented; 1006} 1007 1008OMX_ERRORTYPE ComponentBase::ComponentRoleEnum( 1009 OMX_IN OMX_HANDLETYPE hComponent, 1010 OMX_OUT OMX_U8 *cRole, 1011 OMX_IN OMX_U32 nIndex) 1012{ 1013 ComponentBase *cbase; 1014 1015 if (!hComponent) 1016 return OMX_ErrorBadParameter; 1017 1018 cbase = static_cast<ComponentBase *> 1019 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 1020 if (!cbase) 1021 return OMX_ErrorBadParameter; 1022 1023 return cbase->CBaseComponentRoleEnum(hComponent, cRole, nIndex); 1024} 1025 1026OMX_ERRORTYPE ComponentBase::CBaseComponentRoleEnum( 1027 OMX_IN OMX_HANDLETYPE hComponent, 1028 OMX_OUT OMX_U8 *cRole, 1029 OMX_IN OMX_U32 nIndex) 1030{ 1031 if (hComponent != (OMX_HANDLETYPE *)this->handle) 1032 return OMX_ErrorBadParameter; 1033 1034 if (nIndex > nr_roles) 1035 return OMX_ErrorBadParameter; 1036 1037 strncpy((char *)cRole, (const char *)roles[nIndex], 1038 OMX_MAX_STRINGNAME_SIZE); 1039 return OMX_ErrorNone; 1040} 1041 1042/* implement CmdHandlerInterface */ 1043void ComponentBase::CmdHandler(struct cmd_s *cmd) 1044{ 1045 OMX_EVENTTYPE event = OMX_EventCmdComplete; 1046 OMX_U32 data1 = cmd->cmd, data2 = cmd->param1; 1047 OMX_PTR eventdata = NULL; 1048 1049 switch (cmd->cmd) { 1050 case OMX_CommandStateSet: 1051 /* 1052 * Todo 1053 */ 1054 break; 1055 case OMX_CommandFlush: 1056 /* 1057 * Todo 1058 */ 1059 break; 1060 case OMX_CommandPortDisable: 1061 /* 1062 * Todo 1063 */ 1064 break; 1065 case OMX_CommandPortEnable: 1066 /* 1067 * Todo 1068 */ 1069 break; 1070 case OMX_CommandMarkBuffer: 1071 /* 1072 * Todo 1073 */ 1074 break; 1075 } 1076 1077 callbacks->EventHandler(handle, appdata, 1078 event, data1, data2, eventdata); 1079} 1080 1081/* end of component methods & helpers */ 1082 1083/* 1084 * omx header manipuation 1085 */ 1086void ComponentBase::SetTypeHeader(OMX_PTR type, OMX_U32 size) 1087{ 1088 OMX_U32 *nsize; 1089 OMX_VERSIONTYPE *nversion; 1090 1091 if (!type) 1092 return; 1093 1094 nsize = (OMX_U32 *)type; 1095 nversion = (OMX_VERSIONTYPE *)((OMX_U8 *)type + sizeof(OMX_U32)); 1096 1097 *nsize = sizeof(size); 1098 nversion->nVersion = OMX_SPEC_VERSION; 1099} 1100 1101OMX_BOOL ComponentBase::CheckTypeHeader(OMX_PTR type, OMX_U32 size) 1102{ 1103 OMX_U32 *nsize; 1104 OMX_VERSIONTYPE *nversion; 1105 OMX_U8 mismatch = 0; 1106 1107 if (!type) 1108 return OMX_FALSE; 1109 1110 nsize = (OMX_U32 *)type; 1111 nversion = (OMX_VERSIONTYPE *)((OMX_U8 *)type + sizeof(OMX_U32)); 1112 1113 mismatch = (*nsize != sizeof(size)) ? 1 : 0; 1114 mismatch |= (nversion->nVersion != OMX_SPEC_VERSION) ? 1 : 0; 1115 1116 if (mismatch) 1117 return OMX_TRUE; 1118 else 1119 return OMX_FALSE; 1120} 1121 1122/* end of ComponentBase */ 1123