componentbase.cpp revision d8b921cd23e85c61acf2422a617943ac378cccc4
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 /* 613 * Todo 614 */ 615 616 return OMX_ErrorNotImplemented; 617} 618 619OMX_ERRORTYPE ComponentBase::SetConfig( 620 OMX_IN OMX_HANDLETYPE hComponent, 621 OMX_IN OMX_INDEXTYPE nIndex, 622 OMX_IN OMX_PTR pComponentConfigStructure) 623{ 624 ComponentBase *cbase; 625 626 if (!hComponent) 627 return OMX_ErrorBadParameter; 628 629 cbase = static_cast<ComponentBase *> 630 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 631 if (!cbase) 632 return OMX_ErrorBadParameter; 633 634 return cbase->CBaseSetConfig(hComponent, nIndex, 635 pComponentConfigStructure); 636} 637 638OMX_ERRORTYPE ComponentBase::CBaseSetConfig( 639 OMX_IN OMX_HANDLETYPE hComponent, 640 OMX_IN OMX_INDEXTYPE nIndex, 641 OMX_IN OMX_PTR pComponentConfigStructure) 642{ 643 /* 644 * Todo 645 */ 646 647 return OMX_ErrorNotImplemented; 648} 649 650OMX_ERRORTYPE ComponentBase::GetExtensionIndex( 651 OMX_IN OMX_HANDLETYPE hComponent, 652 OMX_IN OMX_STRING cParameterName, 653 OMX_OUT OMX_INDEXTYPE* pIndexType) 654{ 655 ComponentBase *cbase; 656 657 if (!hComponent) 658 return OMX_ErrorBadParameter; 659 660 cbase = static_cast<ComponentBase *> 661 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 662 if (!cbase) 663 return OMX_ErrorBadParameter; 664 665 return cbase->CBaseGetExtensionIndex(hComponent, cParameterName, 666 pIndexType); 667} 668 669OMX_ERRORTYPE ComponentBase::CBaseGetExtensionIndex( 670 OMX_IN OMX_HANDLETYPE hComponent, 671 OMX_IN OMX_STRING cParameterName, 672 OMX_OUT OMX_INDEXTYPE* pIndexType) 673{ 674 /* 675 * Todo 676 */ 677 678 return OMX_ErrorNotImplemented; 679} 680 681OMX_ERRORTYPE ComponentBase::GetState( 682 OMX_IN OMX_HANDLETYPE hComponent, 683 OMX_OUT OMX_STATETYPE* pState) 684{ 685 ComponentBase *cbase; 686 687 if (!hComponent) 688 return OMX_ErrorBadParameter; 689 690 cbase = static_cast<ComponentBase *> 691 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 692 if (!cbase) 693 return OMX_ErrorBadParameter; 694 695 return cbase->CBaseGetState(hComponent, pState); 696} 697 698OMX_ERRORTYPE ComponentBase::CBaseGetState( 699 OMX_IN OMX_HANDLETYPE hComponent, 700 OMX_OUT OMX_STATETYPE* pState) 701{ 702 /* 703 * Todo 704 */ 705 706 return OMX_ErrorNotImplemented; 707} 708 709OMX_ERRORTYPE ComponentBase::ComponentTunnelRequest( 710 OMX_IN OMX_HANDLETYPE hComponent, 711 OMX_IN OMX_U32 nPort, 712 OMX_IN OMX_HANDLETYPE hTunneledComponent, 713 OMX_IN OMX_U32 nTunneledPort, 714 OMX_INOUT OMX_TUNNELSETUPTYPE* pTunnelSetup) 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->CBaseComponentTunnelRequest(hComponent, nPort, 727 hTunneledComponent, 728 nTunneledPort, pTunnelSetup); 729} 730 731OMX_ERRORTYPE ComponentBase::CBaseComponentTunnelRequest( 732 OMX_IN OMX_HANDLETYPE hComp, 733 OMX_IN OMX_U32 nPort, 734 OMX_IN OMX_HANDLETYPE hTunneledComp, 735 OMX_IN OMX_U32 nTunneledPort, 736 OMX_INOUT OMX_TUNNELSETUPTYPE* pTunnelSetup) 737{ 738 /* 739 * Todo 740 */ 741 742 return OMX_ErrorNotImplemented; 743} 744 745OMX_ERRORTYPE ComponentBase::UseBuffer( 746 OMX_IN OMX_HANDLETYPE hComponent, 747 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 748 OMX_IN OMX_U32 nPortIndex, 749 OMX_IN OMX_PTR pAppPrivate, 750 OMX_IN OMX_U32 nSizeBytes, 751 OMX_IN OMX_U8* pBuffer) 752{ 753 ComponentBase *cbase; 754 755 if (!hComponent) 756 return OMX_ErrorBadParameter; 757 758 cbase = static_cast<ComponentBase *> 759 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 760 if (!cbase) 761 return OMX_ErrorBadParameter; 762 763 return cbase->CBaseUseBuffer(hComponent, ppBufferHdr, nPortIndex, 764 pAppPrivate, nSizeBytes, pBuffer); 765} 766 767OMX_ERRORTYPE ComponentBase::CBaseUseBuffer( 768 OMX_IN OMX_HANDLETYPE hComponent, 769 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 770 OMX_IN OMX_U32 nPortIndex, 771 OMX_IN OMX_PTR pAppPrivate, 772 OMX_IN OMX_U32 nSizeBytes, 773 OMX_IN OMX_U8* pBuffer) 774{ 775 /* 776 * Todo 777 */ 778 779 return OMX_ErrorNotImplemented; 780} 781 782OMX_ERRORTYPE ComponentBase::AllocateBuffer( 783 OMX_IN OMX_HANDLETYPE hComponent, 784 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBuffer, 785 OMX_IN OMX_U32 nPortIndex, 786 OMX_IN OMX_PTR pAppPrivate, 787 OMX_IN OMX_U32 nSizeBytes) 788{ 789 ComponentBase *cbase; 790 791 if (!hComponent) 792 return OMX_ErrorBadParameter; 793 794 cbase = static_cast<ComponentBase *> 795 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 796 if (!cbase) 797 return OMX_ErrorBadParameter; 798 799 return cbase->CBaseAllocateBuffer(hComponent, ppBuffer, nPortIndex, 800 pAppPrivate, nSizeBytes); 801} 802 803OMX_ERRORTYPE ComponentBase::CBaseAllocateBuffer( 804 OMX_IN OMX_HANDLETYPE hComponent, 805 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBuffer, 806 OMX_IN OMX_U32 nPortIndex, 807 OMX_IN OMX_PTR pAppPrivate, 808 OMX_IN OMX_U32 nSizeBytes) 809{ 810 /* 811 * Todo 812 */ 813 814 return OMX_ErrorNotImplemented; 815} 816 817OMX_ERRORTYPE ComponentBase::FreeBuffer( 818 OMX_IN OMX_HANDLETYPE hComponent, 819 OMX_IN OMX_U32 nPortIndex, 820 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 821{ 822 ComponentBase *cbase; 823 824 if (!hComponent) 825 return OMX_ErrorBadParameter; 826 827 cbase = static_cast<ComponentBase *> 828 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 829 if (!cbase) 830 return OMX_ErrorBadParameter; 831 832 return cbase->CBaseFreeBuffer(hComponent, nPortIndex, pBuffer); 833} 834 835OMX_ERRORTYPE ComponentBase::CBaseFreeBuffer( 836 OMX_IN OMX_HANDLETYPE hComponent, 837 OMX_IN OMX_U32 nPortIndex, 838 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 839{ 840 /* 841 * Todo 842 */ 843 844 return OMX_ErrorNotImplemented; 845} 846 847OMX_ERRORTYPE ComponentBase::EmptyThisBuffer( 848 OMX_IN OMX_HANDLETYPE hComponent, 849 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 850{ 851 ComponentBase *cbase; 852 853 if (!hComponent) 854 return OMX_ErrorBadParameter; 855 856 cbase = static_cast<ComponentBase *> 857 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 858 if (!cbase) 859 return OMX_ErrorBadParameter; 860 861 return cbase->CBaseEmptyThisBuffer(hComponent, pBuffer); 862} 863 864OMX_ERRORTYPE ComponentBase::CBaseEmptyThisBuffer( 865 OMX_IN OMX_HANDLETYPE hComponent, 866 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 867{ 868 /* 869 * Todo 870 */ 871 872 return OMX_ErrorNotImplemented; 873} 874 875OMX_ERRORTYPE ComponentBase::FillThisBuffer( 876 OMX_IN OMX_HANDLETYPE hComponent, 877 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 878{ 879 ComponentBase *cbase; 880 881 if (!hComponent) 882 return OMX_ErrorBadParameter; 883 884 cbase = static_cast<ComponentBase *> 885 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 886 if (!cbase) 887 return OMX_ErrorBadParameter; 888 889 return cbase->CBaseFillThisBuffer(hComponent, pBuffer); 890} 891 892OMX_ERRORTYPE ComponentBase::CBaseFillThisBuffer( 893 OMX_IN OMX_HANDLETYPE hComponent, 894 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 895{ 896 /* 897 * Todo 898 */ 899 900 return OMX_ErrorNotImplemented; 901} 902 903OMX_ERRORTYPE ComponentBase::SetCallbacks( 904 OMX_IN OMX_HANDLETYPE hComponent, 905 OMX_IN OMX_CALLBACKTYPE* pCallbacks, 906 OMX_IN OMX_PTR pAppData) 907{ 908 ComponentBase *cbase; 909 910 if (!hComponent) 911 return OMX_ErrorBadParameter; 912 913 cbase = static_cast<ComponentBase *> 914 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 915 if (!cbase) 916 return OMX_ErrorBadParameter; 917 918 return cbase->CBaseSetCallbacks(hComponent, pCallbacks, pAppData); 919} 920 921OMX_ERRORTYPE ComponentBase::CBaseSetCallbacks( 922 OMX_IN OMX_HANDLETYPE hComponent, 923 OMX_IN OMX_CALLBACKTYPE *pCallbacks, 924 OMX_IN OMX_PTR pAppData) 925{ 926 if (hComponent != handle) 927 return OMX_ErrorBadParameter; 928 929 appdata = pAppData; 930 callbacks = pCallbacks; 931 932 return OMX_ErrorNone; 933} 934 935OMX_ERRORTYPE ComponentBase::ComponentDeInit( 936 OMX_IN OMX_HANDLETYPE hComponent) 937{ 938 ComponentBase *cbase; 939 940 if (!hComponent) 941 return OMX_ErrorBadParameter; 942 943 cbase = static_cast<ComponentBase *> 944 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 945 if (!cbase) 946 return OMX_ErrorBadParameter; 947 948 return cbase->CBaseComponentDeInit(hComponent); 949} 950 951OMX_ERRORTYPE ComponentBase::CBaseComponentDeInit( 952 OMX_IN OMX_HANDLETYPE hComponent) 953{ 954 /* 955 * Todo 956 */ 957 958 return OMX_ErrorNotImplemented; 959} 960 961OMX_ERRORTYPE ComponentBase::UseEGLImage( 962 OMX_IN OMX_HANDLETYPE hComponent, 963 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 964 OMX_IN OMX_U32 nPortIndex, 965 OMX_IN OMX_PTR pAppPrivate, 966 OMX_IN void* eglImage) 967{ 968 ComponentBase *cbase; 969 970 if (!hComponent) 971 return OMX_ErrorBadParameter; 972 973 cbase = static_cast<ComponentBase *> 974 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 975 if (!cbase) 976 return OMX_ErrorBadParameter; 977 978 return cbase->CBaseUseEGLImage(hComponent, ppBufferHdr, nPortIndex, 979 pAppPrivate, eglImage); 980} 981 982OMX_ERRORTYPE ComponentBase::CBaseUseEGLImage( 983 OMX_IN OMX_HANDLETYPE hComponent, 984 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 985 OMX_IN OMX_U32 nPortIndex, 986 OMX_IN OMX_PTR pAppPrivate, 987 OMX_IN void* eglImage) 988{ 989 /* 990 * Todo 991 */ 992 993 return OMX_ErrorNotImplemented; 994} 995 996OMX_ERRORTYPE ComponentBase::ComponentRoleEnum( 997 OMX_IN OMX_HANDLETYPE hComponent, 998 OMX_OUT OMX_U8 *cRole, 999 OMX_IN OMX_U32 nIndex) 1000{ 1001 ComponentBase *cbase; 1002 1003 if (!hComponent) 1004 return OMX_ErrorBadParameter; 1005 1006 cbase = static_cast<ComponentBase *> 1007 (((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate); 1008 if (!cbase) 1009 return OMX_ErrorBadParameter; 1010 1011 return cbase->CBaseComponentRoleEnum(hComponent, cRole, nIndex); 1012} 1013 1014OMX_ERRORTYPE ComponentBase::CBaseComponentRoleEnum( 1015 OMX_IN OMX_HANDLETYPE hComponent, 1016 OMX_OUT OMX_U8 *cRole, 1017 OMX_IN OMX_U32 nIndex) 1018{ 1019 if (hComponent != (OMX_HANDLETYPE *)this->handle) 1020 return OMX_ErrorBadParameter; 1021 1022 if (nIndex > nr_roles) 1023 return OMX_ErrorBadParameter; 1024 1025 strncpy((char *)cRole, (const char *)roles[nIndex], 1026 OMX_MAX_STRINGNAME_SIZE); 1027 return OMX_ErrorNone; 1028} 1029 1030/* implement CmdHandlerInterface */ 1031void ComponentBase::CmdHandler(struct cmd_s *cmd) 1032{ 1033 OMX_EVENTTYPE event = OMX_EventCmdComplete; 1034 OMX_U32 data1 = cmd->cmd, data2 = cmd->param1; 1035 OMX_PTR eventdata = NULL; 1036 1037 switch (cmd->cmd) { 1038 case OMX_CommandStateSet: 1039 /* 1040 * Todo 1041 */ 1042 break; 1043 case OMX_CommandFlush: 1044 /* 1045 * Todo 1046 */ 1047 break; 1048 case OMX_CommandPortDisable: 1049 /* 1050 * Todo 1051 */ 1052 break; 1053 case OMX_CommandPortEnable: 1054 /* 1055 * Todo 1056 */ 1057 break; 1058 case OMX_CommandMarkBuffer: 1059 /* 1060 * Todo 1061 */ 1062 break; 1063 } 1064 1065 callbacks->EventHandler(handle, appdata, 1066 event, data1, data2, eventdata); 1067} 1068 1069/* end of component methods & helpers */ 1070 1071/* 1072 * omx header manipuation 1073 */ 1074void ComponentBase::SetTypeHeader(OMX_PTR type, OMX_U32 size) 1075{ 1076 OMX_U32 *nsize; 1077 OMX_VERSIONTYPE *nversion; 1078 1079 if (!type) 1080 return; 1081 1082 nsize = (OMX_U32 *)type; 1083 nversion = (OMX_VERSIONTYPE *)((OMX_U8 *)type + sizeof(OMX_U32)); 1084 1085 *nsize = sizeof(size); 1086 nversion->nVersion = OMX_SPEC_VERSION; 1087} 1088 1089OMX_BOOL ComponentBase::CheckTypeHeader(OMX_PTR type, OMX_U32 size) 1090{ 1091 OMX_U32 *nsize; 1092 OMX_VERSIONTYPE *nversion; 1093 OMX_U8 mismatch = 0; 1094 1095 if (!type) 1096 return OMX_FALSE; 1097 1098 nsize = (OMX_U32 *)type; 1099 nversion = (OMX_VERSIONTYPE *)((OMX_U8 *)type + sizeof(OMX_U32)); 1100 1101 mismatch = (*nsize != sizeof(size)) ? 1 : 0; 1102 mismatch |= (nversion->nVersion != OMX_SPEC_VERSION) ? 1 : 0; 1103 1104 if (mismatch) 1105 return OMX_TRUE; 1106 else 1107 return OMX_FALSE; 1108} 1109 1110/* end of ComponentBase */ 1111