diff options
Diffstat (limited to 'media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp')
-rw-r--r-- | media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp | 349 |
1 files changed, 291 insertions, 58 deletions
diff --git a/media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp b/media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp index 2d91e827..5d0ac35e 100644 --- a/media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp +++ b/media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp | |||
@@ -15,6 +15,10 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #define LOG_TAG "media_omx_hidl_component_test" | 17 | #define LOG_TAG "media_omx_hidl_component_test" |
18 | #ifdef __LP64__ | ||
19 | #define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS | ||
20 | #endif | ||
21 | |||
18 | #include <android-base/logging.h> | 22 | #include <android-base/logging.h> |
19 | 23 | ||
20 | #include <android/hardware/media/omx/1.0/IOmx.h> | 24 | #include <android/hardware/media/omx/1.0/IOmx.h> |
@@ -181,7 +185,7 @@ class ComponentHidlTest : public ::testing::VtsHalHidlTargetTestBase { | |||
181 | strlen(gEnv->getComponent().c_str()) - suffixLen, | 185 | strlen(gEnv->getComponent().c_str()) - suffixLen, |
182 | ".secure"); | 186 | ".secure"); |
183 | } | 187 | } |
184 | if (disableTest) std::cerr << "[ ] Warning ! Test Disabled\n"; | 188 | if (disableTest) std::cout << "[ WARN ] Test Disabled \n"; |
185 | } | 189 | } |
186 | 190 | ||
187 | virtual void TearDown() override { | 191 | virtual void TearDown() override { |
@@ -213,9 +217,6 @@ class ComponentHidlTest : public ::testing::VtsHalHidlTargetTestBase { | |||
213 | } | 217 | } |
214 | }; | 218 | }; |
215 | 219 | ||
216 | // Random Index used for monkey testing while get/set parameters | ||
217 | #define RANDOM_INDEX 1729 | ||
218 | |||
219 | void initPortMode(PortMode* pm, bool isSecure, | 220 | void initPortMode(PortMode* pm, bool isSecure, |
220 | ComponentHidlTest::standardCompClass compClass) { | 221 | ComponentHidlTest::standardCompClass compClass) { |
221 | pm[0] = PortMode::PRESET_BYTE_BUFFER; | 222 | pm[0] = PortMode::PRESET_BYTE_BUFFER; |
@@ -293,7 +294,7 @@ TEST_F(ComponentHidlTest, DISABLED_GetPortIndices) { | |||
293 | } | 294 | } |
294 | 295 | ||
295 | // port format enumeration | 296 | // port format enumeration |
296 | TEST_F(ComponentHidlTest, DISABLED_EnumeratePortFormat) { | 297 | TEST_F(ComponentHidlTest, EnumeratePortFormat) { |
297 | description("Test Component on Mandatory Port Parameters (Port Format)"); | 298 | description("Test Component on Mandatory Port Parameters (Port Format)"); |
298 | if (disableTest) return; | 299 | if (disableTest) return; |
299 | android::hardware::media::omx::V1_0::Status status; | 300 | android::hardware::media::omx::V1_0::Status status; |
@@ -374,7 +375,7 @@ TEST_F(ComponentHidlTest, DISABLED_SetDefaultPortParams) { | |||
374 | kPortIndexOutput = kPortIndexInput + 1; | 375 | kPortIndexOutput = kPortIndexInput + 1; |
375 | } | 376 | } |
376 | 377 | ||
377 | for (size_t i = kPortIndexInput; i < kPortIndexOutput; i++) { | 378 | for (size_t i = kPortIndexInput; i <= kPortIndexOutput; i++) { |
378 | OMX_PARAM_PORTDEFINITIONTYPE portDef; | 379 | OMX_PARAM_PORTDEFINITIONTYPE portDef; |
379 | status = | 380 | status = |
380 | getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); | 381 | getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); |
@@ -400,28 +401,30 @@ TEST_F(ComponentHidlTest, DISABLED_SetDefaultPortParams) { | |||
400 | EXPECT_NE(status, | 401 | EXPECT_NE(status, |
401 | ::android::hardware::media::omx::V1_0::Status::OK); | 402 | ::android::hardware::media::omx::V1_0::Status::OK); |
402 | 403 | ||
403 | // Edit Read-Only fields. | 404 | // Port Direction - Read Only |
404 | portDef = mirror; | 405 | portDef = mirror; |
405 | portDef.eDir = static_cast<OMX_DIRTYPE>(RANDOM_INDEX); | 406 | portDef.eDir = static_cast<OMX_DIRTYPE>(RANDOM_INDEX); |
406 | setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); | 407 | setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); |
407 | getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); | 408 | getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); |
408 | EXPECT_EQ(portDef.eDir, mirror.eDir); | 409 | if (portDef.eDir != mirror.eDir) { |
409 | setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror); | 410 | std::cerr << "[ ERROR ] port direction has to be read only " |
410 | 411 | "but is changeable \n"; | |
411 | portDef = mirror; | 412 | } |
412 | portDef.nBufferSize >>= 1; | ||
413 | setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); | ||
414 | getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); | ||
415 | EXPECT_EQ(portDef.nBufferSize, mirror.nBufferSize); | ||
416 | setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror); | 413 | setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror); |
417 | 414 | ||
415 | // Port Min BufferCount - Read Only | ||
418 | portDef = mirror; | 416 | portDef = mirror; |
419 | portDef.nBufferCountMin += 1; | 417 | portDef.nBufferCountMin += 1; |
420 | setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); | 418 | setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); |
421 | getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); | 419 | getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); |
420 | if (portDef.nBufferCountMin != mirror.nBufferCountMin) { | ||
421 | std::cerr << "[ ERROR ] port Min BufferCount has to be " | ||
422 | "read only but is changeable \n"; | ||
423 | } | ||
422 | EXPECT_EQ(portDef.nBufferCountMin, mirror.nBufferCountMin); | 424 | EXPECT_EQ(portDef.nBufferCountMin, mirror.nBufferCountMin); |
423 | setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror); | 425 | setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror); |
424 | 426 | ||
427 | // Port Actual BufferCount | ||
425 | portDef = mirror; | 428 | portDef = mirror; |
426 | portDef.nBufferCountActual += 1; | 429 | portDef.nBufferCountActual += 1; |
427 | status = setPortParam(omxNode, OMX_IndexParamPortDefinition, i, | 430 | status = setPortParam(omxNode, OMX_IndexParamPortDefinition, i, |
@@ -433,19 +436,47 @@ TEST_F(ComponentHidlTest, DISABLED_SetDefaultPortParams) { | |||
433 | mirror.nBufferCountActual + 1); | 436 | mirror.nBufferCountActual + 1); |
434 | } | 437 | } |
435 | 438 | ||
439 | // Port BufferSize is although read only as per OMX-IL 1.2, android | ||
440 | // doesnt abide by this. | ||
441 | // Decrease buffer size | ||
436 | portDef = mirror; | 442 | portDef = mirror; |
437 | portDef.nBufferSize = mirror.nBufferSize << 1; | 443 | OMX_U32 nBufferSize = portDef.nBufferSize >> 1; |
438 | status = setPortParam(omxNode, OMX_IndexParamPortDefinition, i, | 444 | if (nBufferSize != 0) { |
439 | &portDef); | 445 | if (!strncmp(gEnv->getComponent().c_str(), "OMX.google.", 11)) { |
440 | if (status == ::android::hardware::media::omx::V1_0::Status::OK) { | 446 | portDef.nBufferSize = nBufferSize; |
441 | status = getPortParam(omxNode, OMX_IndexParamPortDefinition, i, | 447 | } else { |
442 | &portDef); | 448 | // Probable alignment requirements of vendor component |
443 | if (portDef.nBufferSize != mirror.nBufferSize) { | 449 | portDef.nBufferSize = ALIGN_POWER_OF_TWO(nBufferSize, 12); |
444 | std::cout | 450 | nBufferSize = portDef.nBufferSize; |
445 | << "[ ] Warning ! Component input port does " | 451 | } |
446 | "not preserve Read-Only fields \n"; | 452 | } else { |
453 | ASSERT_TRUE(false) << "Unexpected buffer size"; | ||
454 | } | ||
455 | setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); | ||
456 | getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); | ||
457 | // SPECIAL CASE: For video decoder, allow configuration of input | ||
458 | // buffer size even if it is less than minimum requirement and | ||
459 | // similarly for encoder allow configuration of output port buffer | ||
460 | // size. | ||
461 | if ((compClass == video_encoder && i == kPortIndexOutput) || | ||
462 | (compClass == video_decoder && i == kPortIndexInput)) { | ||
463 | double dev = (portDef.nBufferSize / (double)nBufferSize); | ||
464 | dev -= 1; | ||
465 | if (dev < 0 || dev > 0.1) { | ||
466 | std::cerr << "[ ERROR ] port buffer size deviation " | ||
467 | "larger than expected \n"; | ||
447 | } | 468 | } |
469 | } else { | ||
470 | EXPECT_EQ(portDef.nBufferSize, mirror.nBufferSize); | ||
448 | } | 471 | } |
472 | setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &mirror); | ||
473 | |||
474 | // Increase buffer size | ||
475 | portDef = mirror; | ||
476 | portDef.nBufferSize = mirror.nBufferSize << 1; | ||
477 | setPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); | ||
478 | getPortParam(omxNode, OMX_IndexParamPortDefinition, i, &portDef); | ||
479 | EXPECT_EQ(portDef.nBufferSize, (mirror.nBufferSize << 1)); | ||
449 | } | 480 | } |
450 | } | 481 | } |
451 | } | 482 | } |
@@ -470,8 +501,10 @@ TEST_F(ComponentHidlTest, DISABLED_PopulatePort) { | |||
470 | portBase = params.nStartPortNumber; | 501 | portBase = params.nStartPortNumber; |
471 | } | 502 | } |
472 | 503 | ||
473 | sp<IAllocator> allocator = IAllocator::getService("ashmem"); | 504 | // set state to idle |
474 | EXPECT_NE(allocator.get(), nullptr); | 505 | status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet), |
506 | OMX_StateIdle); | ||
507 | ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); | ||
475 | 508 | ||
476 | OMX_PARAM_PORTDEFINITIONTYPE portDef; | 509 | OMX_PARAM_PORTDEFINITIONTYPE portDef; |
477 | status = | 510 | status = |
@@ -485,30 +518,9 @@ TEST_F(ComponentHidlTest, DISABLED_PopulatePort) { | |||
485 | 518 | ||
486 | for (size_t i = 0; i < portDef.nBufferCountActual; i++) { | 519 | for (size_t i = 0; i < portDef.nBufferCountActual; i++) { |
487 | BufferInfo buffer; | 520 | BufferInfo buffer; |
488 | buffer.owner = client; | 521 | allocateBuffer(omxNode, &buffer, portBase, nBufferSize, |
489 | buffer.omxBuffer.type = CodecBuffer::Type::SHARED_MEM; | 522 | PortMode::PRESET_BYTE_BUFFER); |
490 | buffer.omxBuffer.attr.preset.rangeOffset = 0; | ||
491 | buffer.omxBuffer.attr.preset.rangeLength = 0; | ||
492 | bool success = false; | ||
493 | allocator->allocate( | ||
494 | nBufferSize, | ||
495 | [&success, &buffer](bool _s, | ||
496 | ::android::hardware::hidl_memory const& mem) { | ||
497 | success = _s; | ||
498 | buffer.omxBuffer.sharedMemory = mem; | ||
499 | }); | ||
500 | ASSERT_EQ(success, true); | ||
501 | ASSERT_EQ(buffer.omxBuffer.sharedMemory.size(), nBufferSize); | ||
502 | |||
503 | omxNode->useBuffer( | ||
504 | portBase, buffer.omxBuffer, | ||
505 | [&status, &buffer](android::hardware::media::omx::V1_0::Status _s, | ||
506 | uint32_t id) { | ||
507 | status = _s; | ||
508 | buffer.id = id; | ||
509 | }); | ||
510 | pBuffer.push(buffer); | 523 | pBuffer.push(buffer); |
511 | ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
512 | } | 524 | } |
513 | 525 | ||
514 | status = | 526 | status = |
@@ -583,9 +595,9 @@ TEST_F(ComponentHidlTest, Flush) { | |||
583 | kPortIndexInput, kPortIndexOutput); | 595 | kPortIndexInput, kPortIndexOutput); |
584 | } | 596 | } |
585 | 597 | ||
586 | // state transitions test | 598 | // Flush test - monkeying |
587 | TEST_F(ComponentHidlTest, StateTransitions) { | 599 | TEST_F(ComponentHidlTest, Flush_M) { |
588 | description("Test State Transitions Loaded<->Idle<->Execute"); | 600 | description("Test Flush monkeying"); |
589 | if (disableTest) return; | 601 | if (disableTest) return; |
590 | android::hardware::media::omx::V1_0::Status status; | 602 | android::hardware::media::omx::V1_0::Status status; |
591 | uint32_t kPortIndexInput = 0, kPortIndexOutput = 1; | 603 | uint32_t kPortIndexInput = 0, kPortIndexOutput = 1; |
@@ -615,29 +627,250 @@ TEST_F(ComponentHidlTest, StateTransitions) { | |||
615 | status = omxNode->setPortMode(kPortIndexOutput, portMode[1]); | 627 | status = omxNode->setPortMode(kPortIndexOutput, portMode[1]); |
616 | EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); | 628 | EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); |
617 | 629 | ||
630 | // // Flush all ports ; receive error OMX_ErrorIncorrectStateOperation | ||
631 | // status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush), | ||
632 | // OMX_ALL); | ||
633 | // ASSERT_NE(status, android::hardware::media::omx::V1_0::Status::OK); | ||
634 | |||
618 | // set state to idle | 635 | // set state to idle |
619 | changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, | 636 | changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, |
620 | kPortIndexInput, kPortIndexOutput, portMode); | 637 | kPortIndexInput, kPortIndexOutput, portMode); |
638 | |||
639 | // // Flush all ports ; receive error OMX_ErrorIncorrectStateOperation | ||
640 | // status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush), | ||
641 | // OMX_ALL); | ||
642 | // ASSERT_NE(status, android::hardware::media::omx::V1_0::Status::OK); | ||
643 | |||
621 | // set state to executing | 644 | // set state to executing |
622 | changeStateIdletoExecute(omxNode, observer); | 645 | changeStateIdletoExecute(omxNode, observer); |
623 | // dispatch buffers | 646 | // dispatch buffers |
624 | for (size_t i = 0; i < oBuffer.size(); i++) { | 647 | for (size_t i = 0; i < oBuffer.size(); i++) { |
625 | dispatchOutputBuffer(omxNode, &oBuffer, i, portMode[1]); | 648 | dispatchOutputBuffer(omxNode, &oBuffer, i, portMode[1]); |
626 | } | 649 | } |
650 | |||
651 | // // flush invalid port, expecting OMX_ErrorBadPortIndex | ||
652 | // status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush), | ||
653 | // RANDOM_INDEX); | ||
654 | // ASSERT_NE(status, android::hardware::media::omx::V1_0::Status::OK); | ||
655 | |||
656 | // Flush all ports | ||
657 | status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush), OMX_ALL); | ||
658 | ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); | ||
659 | |||
660 | for (int j = 0; j < 2; j++) { | ||
661 | status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_PE, &iBuffer, | ||
662 | &oBuffer); | ||
663 | ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); | ||
664 | ASSERT_EQ(msg.type, Message::Type::EVENT); | ||
665 | ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete); | ||
666 | ASSERT_EQ(msg.data.eventData.data1, OMX_CommandFlush); | ||
667 | if (msg.data.eventData.data2 == kPortIndexInput) { | ||
668 | // test if client got all its buffers back | ||
669 | for (size_t i = 0; i < iBuffer.size(); ++i) { | ||
670 | EXPECT_EQ(iBuffer[i].owner, client); | ||
671 | } | ||
672 | } else if (msg.data.eventData.data2 == kPortIndexOutput) { | ||
673 | // test if client got all its buffers back | ||
674 | for (size_t i = 0; i < oBuffer.size(); ++i) { | ||
675 | EXPECT_EQ(oBuffer[i].owner, client); | ||
676 | } | ||
677 | } else { | ||
678 | EXPECT_TRUE(false) << "Bad port Index"; | ||
679 | } | ||
680 | } | ||
681 | |||
682 | // SPECIAL CASE: When OMX_ALL is used as argument, Android OMX Core sends | ||
683 | // an additional flush event with argument OMX_ALL. This we believe is | ||
684 | // not recognized by OMX-IL Spec. So read this event and ignore it | ||
685 | status = | ||
686 | observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_PE, &iBuffer, &oBuffer); | ||
687 | if (status == android::hardware::media::omx::V1_0::Status::OK) { | ||
688 | ASSERT_EQ(msg.type, Message::Type::EVENT); | ||
689 | ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete); | ||
690 | ASSERT_EQ(msg.data.eventData.data1, OMX_CommandFlush); | ||
691 | ASSERT_EQ(msg.data.eventData.data2, OMX_ALL); | ||
692 | } | ||
693 | |||
627 | // set state to idle | 694 | // set state to idle |
628 | changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); | 695 | changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); |
696 | // set state to loaded | ||
697 | changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, | ||
698 | kPortIndexInput, kPortIndexOutput); | ||
699 | } | ||
700 | |||
701 | // test port mode configuration when the component is in various states | ||
702 | TEST_F(ComponentHidlTest, PortModeConfig) { | ||
703 | description("Test Port Mode Configuration"); | ||
704 | if (disableTest) return; | ||
705 | android::hardware::media::omx::V1_0::Status status; | ||
706 | uint32_t kPortIndexInput = 0, kPortIndexOutput = 1; | ||
707 | Message msg; | ||
708 | |||
709 | status = setRole(omxNode, gEnv->getRole().c_str()); | ||
710 | ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
711 | OMX_PORT_PARAM_TYPE params; | ||
712 | if (compClass == audio_decoder || compClass == audio_encoder) { | ||
713 | status = getParam(omxNode, OMX_IndexParamAudioInit, ¶ms); | ||
714 | } else { | ||
715 | status = getParam(omxNode, OMX_IndexParamVideoInit, ¶ms); | ||
716 | } | ||
717 | if (status == ::android::hardware::media::omx::V1_0::Status::OK) { | ||
718 | ASSERT_EQ(params.nPorts, 2U); | ||
719 | kPortIndexInput = params.nStartPortNumber; | ||
720 | kPortIndexOutput = kPortIndexInput + 1; | ||
721 | } | ||
722 | |||
723 | android::Vector<BufferInfo> iBuffer, oBuffer; | ||
724 | |||
725 | // set port mode | ||
726 | PortMode portMode[2]; | ||
727 | initPortMode(portMode, isSecure, compClass); | ||
728 | status = omxNode->setPortMode(kPortIndexInput, portMode[0]); | ||
729 | EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
730 | status = omxNode->setPortMode(kPortIndexOutput, portMode[1]); | ||
731 | EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
732 | |||
733 | // set state to idle | ||
734 | changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer, | ||
735 | kPortIndexInput, kPortIndexOutput, portMode); | ||
736 | // Only Allow Port Mode configuration in loaded state | ||
737 | status = omxNode->setPortMode(kPortIndexInput, portMode[0]); | ||
738 | EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
739 | status = omxNode->setPortMode(kPortIndexOutput, portMode[1]); | ||
740 | EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
741 | |||
742 | // set state to executing | ||
743 | changeStateIdletoExecute(omxNode, observer); | ||
744 | // Only Allow Port Mode configuration in loaded state | ||
745 | status = omxNode->setPortMode(kPortIndexInput, portMode[0]); | ||
746 | EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
747 | status = omxNode->setPortMode(kPortIndexOutput, portMode[1]); | ||
748 | EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
749 | |||
750 | // set state to idle | ||
751 | changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); | ||
752 | // set state to loaded | ||
753 | changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, | ||
754 | kPortIndexInput, kPortIndexOutput); | ||
755 | |||
756 | status = omxNode->setPortMode(kPortIndexInput, portMode[0]); | ||
757 | EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
758 | status = omxNode->setPortMode(kPortIndexOutput, portMode[1]); | ||
759 | EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
760 | } | ||
761 | |||
762 | // state transitions test | ||
763 | TEST_F(ComponentHidlTest, StateTransitions) { | ||
764 | description("Test State Transitions Loaded<->Idle<->Execute"); | ||
765 | if (disableTest) return; | ||
766 | android::hardware::media::omx::V1_0::Status status; | ||
767 | uint32_t kPortIndexInput = 0, kPortIndexOutput = 1; | ||
768 | OMX_U32 portBase = 0; | ||
769 | Message msg; | ||
770 | status = setRole(omxNode, gEnv->getRole().c_str()); | ||
771 | ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
772 | OMX_PORT_PARAM_TYPE params; | ||
773 | if (compClass == audio_decoder || compClass == audio_encoder) { | ||
774 | status = getParam(omxNode, OMX_IndexParamAudioInit, ¶ms); | ||
775 | } else { | ||
776 | status = getParam(omxNode, OMX_IndexParamVideoInit, ¶ms); | ||
777 | } | ||
778 | if (status == ::android::hardware::media::omx::V1_0::Status::OK) { | ||
779 | ASSERT_EQ(params.nPorts, 2U); | ||
780 | portBase = params.nStartPortNumber; | ||
781 | } | ||
782 | kPortIndexInput = portBase; | ||
783 | kPortIndexOutput = portBase + 1; | ||
784 | |||
785 | android::Vector<BufferInfo> pBuffer[2]; | ||
786 | |||
787 | // set port mode | ||
788 | PortMode portMode[2]; | ||
789 | initPortMode(portMode, isSecure, compClass); | ||
790 | status = omxNode->setPortMode(kPortIndexInput, portMode[0]); | ||
791 | EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
792 | status = omxNode->setPortMode(kPortIndexOutput, portMode[1]); | ||
793 | EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
794 | |||
795 | // set state to idle | ||
796 | status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet), | ||
797 | OMX_StateIdle); | ||
798 | ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); | ||
799 | |||
800 | for (size_t j = portBase; j < portBase + 2; j++) { | ||
801 | pBuffer[j - portBase].clear(); | ||
802 | |||
803 | OMX_PARAM_PORTDEFINITIONTYPE def; | ||
804 | status = getPortParam(omxNode, OMX_IndexParamPortDefinition, j, &def); | ||
805 | ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); | ||
806 | |||
807 | for (size_t i = 0; i < def.nBufferCountActual; i++) { | ||
808 | // Dont switch states until the ports are populated | ||
809 | status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, | ||
810 | &pBuffer[0], &pBuffer[1]); | ||
811 | ASSERT_EQ(status, | ||
812 | android::hardware::media::omx::V1_0::Status::TIMED_OUT); | ||
813 | |||
814 | BufferInfo buffer; | ||
815 | allocateBuffer(omxNode, &buffer, j, def.nBufferSize, | ||
816 | portMode[j - portBase]); | ||
817 | pBuffer[j - portBase].push(buffer); | ||
818 | } | ||
819 | } | ||
820 | |||
821 | // As the ports are populated, check if the state transition is complete | ||
822 | status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, &pBuffer[0], | ||
823 | &pBuffer[1]); | ||
824 | ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); | ||
825 | ASSERT_EQ(msg.type, Message::Type::EVENT); | ||
826 | ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete); | ||
827 | ASSERT_EQ(msg.data.eventData.data1, OMX_CommandStateSet); | ||
828 | ASSERT_EQ(msg.data.eventData.data2, OMX_StateIdle); | ||
829 | |||
830 | // set state to executing | ||
831 | changeStateIdletoExecute(omxNode, observer); | ||
832 | // dispatch buffers | ||
833 | for (size_t i = 0; i < pBuffer[1].size(); i++) { | ||
834 | dispatchOutputBuffer(omxNode, &pBuffer[1], i, portMode[1]); | ||
835 | } | ||
836 | // set state to idle | ||
837 | changeStateExecutetoIdle(omxNode, observer, &pBuffer[0], &pBuffer[1]); | ||
629 | // // set state to executing | 838 | // // set state to executing |
630 | // changeStateIdletoExecute(omxNode, observer); | 839 | // changeStateIdletoExecute(omxNode, observer); |
631 | // // TODO: Sending empty input buffers is slightly tricky. | 840 | // // TODO: Sending empty input buffers is slightly tricky. |
632 | // // dispatch buffers | 841 | // // dispatch buffers |
633 | // for (size_t i = 0; i < iBuffer.size(); i++) { | 842 | // for (size_t i = 0; i < pBuffer[0].size(); i++) { |
634 | // dispatchInputBuffer(omxNode, &iBuffer, i, 0, 0, 0, portMode[0]); | 843 | // dispatchInputBuffer(omxNode, &pBuffer[0], i, 0, 0, 0, |
844 | // portMode[0]); | ||
635 | // } | 845 | // } |
636 | // // set state to idle | 846 | // // set state to idle |
637 | // changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer); | 847 | // changeStateExecutetoIdle(omxNode, observer, &pBuffer[0], &pBuffer[1]); |
848 | |||
638 | // set state to loaded | 849 | // set state to loaded |
639 | changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, | 850 | status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet), |
640 | kPortIndexInput, kPortIndexOutput); | 851 | OMX_StateLoaded); |
852 | ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); | ||
853 | |||
854 | for (size_t j = portBase; j < portBase + 2; j++) { | ||
855 | for (size_t i = 0; i < pBuffer[j].size(); ++i) { | ||
856 | // Dont switch states until the ports are populated | ||
857 | status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, | ||
858 | &pBuffer[0], &pBuffer[1]); | ||
859 | ASSERT_EQ(status, | ||
860 | android::hardware::media::omx::V1_0::Status::TIMED_OUT); | ||
861 | |||
862 | status = omxNode->freeBuffer(j, pBuffer[j][i].id); | ||
863 | ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); | ||
864 | } | ||
865 | } | ||
866 | |||
867 | status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, &pBuffer[0], | ||
868 | &pBuffer[1]); | ||
869 | ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); | ||
870 | ASSERT_EQ(msg.type, Message::Type::EVENT); | ||
871 | ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete); | ||
872 | ASSERT_EQ(msg.data.eventData.data1, OMX_CommandStateSet); | ||
873 | ASSERT_EQ(msg.data.eventData.data2, OMX_StateLoaded); | ||
641 | } | 874 | } |
642 | 875 | ||
643 | // state transitions test - monkeying | 876 | // state transitions test - monkeying |