diff --git a/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp b/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp index 9184c56e70..ea29f038de 100644 --- a/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp +++ b/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp @@ -215,6 +215,7 @@ void allocateGraphicBuffers(sp omxNode, OMX_U32 portIndex, ASSERT_NE(handle, nullptr); *nStride = static_cast(stride); + buffer->handle = handle; buffer->omxBuffer.nativeHandle = handle; buffer->omxBuffer.attr.anwBuffer.width = nFrameWidth; buffer->omxBuffer.attr.anwBuffer.height = nFrameHeight; @@ -335,6 +336,18 @@ void allocatePortBuffers(sp omxNode, } } +// free buffers needed on a component port +void freePortBuffers(android::Vector* buffArray, PortMode portMode, bool allocGrap) { + for (size_t i = 0; i < buffArray->size(); i++) { + if (portMode == PortMode::PRESET_ANW_BUFFER || + (allocGrap && portMode == PortMode::DYNAMIC_ANW_BUFFER)) { + android::GraphicBufferAllocator& allocator = android::GraphicBufferAllocator::get(); + android::status_t error = allocator.free((*buffArray)[i].handle); + ASSERT_EQ(error, android::NO_ERROR); + } + } +} + // State Transition : Loaded -> Idle // Note: This function does not make any background checks for this transition. // The callee holds the reponsibility to ensure the legality of the transition. @@ -399,11 +412,15 @@ void changeStateLoadedtoIdle(sp omxNode, sp observer, // The callee holds the reponsibility to ensure the legality of the transition. void changeStateIdletoLoaded(sp omxNode, sp observer, android::Vector* iBuffer, - android::Vector* oBuffer, - OMX_U32 kPortIndexInput, - OMX_U32 kPortIndexOutput) { + android::Vector* oBuffer, OMX_U32 kPortIndexInput, + OMX_U32 kPortIndexOutput, PortMode* portMode, bool allocGrap) { android::hardware::media::omx::V1_0::Status status; Message msg; + PortMode defaultPortMode[2], *pm; + + defaultPortMode[0] = PortMode::PRESET_BYTE_BUFFER; + defaultPortMode[1] = PortMode::PRESET_BYTE_BUFFER; + pm = portMode ? portMode : defaultPortMode; // set state to Loaded status = omxNode->sendCommand(toRawCommandType(OMX_CommandStateSet), @@ -446,6 +463,8 @@ void changeStateIdletoLoaded(sp omxNode, sp observer, ASSERT_EQ(msg.data.eventData.data1, OMX_CommandStateSet); ASSERT_EQ(msg.data.eventData.data2, OMX_StateLoaded); + ASSERT_NO_FATAL_FAILURE(freePortBuffers(iBuffer, pm[0], allocGrap)); + ASSERT_NO_FATAL_FAILURE(freePortBuffers(oBuffer, pm[1], allocGrap)); return; } diff --git a/media/omx/1.0/vts/functional/common/media_hidl_test_common.h b/media/omx/1.0/vts/functional/common/media_hidl_test_common.h index b16c772512..eddf83f02d 100644 --- a/media/omx/1.0/vts/functional/common/media_hidl_test_common.h +++ b/media/omx/1.0/vts/functional/common/media_hidl_test_common.h @@ -115,6 +115,7 @@ inline uint32_t toRawCommandType(OMX_COMMANDTYPE l) { struct BufferInfo { uint32_t id; bufferOwner owner; + buffer_handle_t handle; android::hardware::media::omx::V1_0::CodecBuffer omxBuffer; ::android::sp mMemory; int32_t slot; @@ -329,6 +330,9 @@ void allocatePortBuffers(sp omxNode, PortMode portMode = PortMode::PRESET_BYTE_BUFFER, bool allocGrap = false); +void freePortBuffers(android::Vector* buffArray, PortMode portMode, + bool allocGrap = false); + void changeStateLoadedtoIdle(sp omxNode, sp observer, android::Vector* iBuffer, android::Vector* oBuffer, @@ -338,8 +342,9 @@ void changeStateLoadedtoIdle(sp omxNode, sp observer, void changeStateIdletoLoaded(sp omxNode, sp observer, android::Vector* iBuffer, - android::Vector* oBuffer, - OMX_U32 kPortIndexInput, OMX_U32 kPortIndexOutput); + android::Vector* oBuffer, OMX_U32 kPortIndexInput, + OMX_U32 kPortIndexOutput, PortMode* portMode = nullptr, + bool allocGrap = false); void changeStateIdletoExecute(sp omxNode, sp observer); diff --git a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp index 67b9895d06..d35ce652fb 100644 --- a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp +++ b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp @@ -451,6 +451,7 @@ void portReconfiguration(sp omxNode, sp observer, status, android::hardware::media::omx::V1_0::Status::TIMED_OUT); + ASSERT_NO_FATAL_FAILURE(freePortBuffers(oBuffer, oPortMode, true)); ASSERT_NO_FATAL_FAILURE(allocatePortBuffers( omxNode, oBuffer, kPortIndexOutput, oPortMode, true)); status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, @@ -853,9 +854,9 @@ TEST_P(VideoDecHidlTest, DecodeTest) { ASSERT_NO_FATAL_FAILURE( changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer)); // set state to executing - ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, - &oBuffer, kPortIndexInput, - kPortIndexOutput)); + ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, + kPortIndexInput, kPortIndexOutput, portMode, + true)); } // Test for adaptive playback support @@ -1001,9 +1002,9 @@ TEST_P(VideoDecHidlTest, AdaptivePlaybackTest) { ASSERT_NO_FATAL_FAILURE( changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer)); // set state to executing - ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, - &oBuffer, kPortIndexInput, - kPortIndexOutput)); + ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, + kPortIndexInput, kPortIndexOutput, portMode, + true)); } // end of sequence test @@ -1067,9 +1068,9 @@ TEST_P(VideoDecHidlTest, EOSTest_M) { ASSERT_NO_FATAL_FAILURE( changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer)); // set state to executing - ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, - &oBuffer, kPortIndexInput, - kPortIndexOutput)); + ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, + kPortIndexInput, kPortIndexOutput, portMode, + true)); } // end of sequence test @@ -1188,9 +1189,9 @@ TEST_P(VideoDecHidlTest, ThumbnailTest) { ASSERT_NO_FATAL_FAILURE( changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer)); // set state to executing - ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, - &oBuffer, kPortIndexInput, - kPortIndexOutput)); + ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, + kPortIndexInput, kPortIndexOutput, portMode, + true)); } // end of sequence test @@ -1295,9 +1296,9 @@ TEST_P(VideoDecHidlTest, SimpleEOSTest) { ASSERT_NO_FATAL_FAILURE( changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer)); // set state to executing - ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, - &oBuffer, kPortIndexInput, - kPortIndexOutput)); + ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, + kPortIndexInput, kPortIndexOutput, portMode, + true)); } // test input/output port flush @@ -1414,9 +1415,9 @@ TEST_P(VideoDecHidlTest, FlushTest) { ASSERT_NO_FATAL_FAILURE( changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer)); // set state to executing - ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, - &oBuffer, kPortIndexInput, - kPortIndexOutput)); + ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, + kPortIndexInput, kPortIndexOutput, portMode, + true)); } GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VideoDecHidlTest); diff --git a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp index 3c0734ebeb..f24c6d1be2 100644 --- a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp +++ b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp @@ -1057,9 +1057,9 @@ TEST_P(VideoEncHidlTest, BufferSourceCallBacks) { ASSERT_NO_FATAL_FAILURE(changeStateExecutetoIdle( omxNode, observer, &buffersource->iBuffer, &buffersource->oBuffer)); // set state to executing - ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded( - omxNode, observer, &buffersource->iBuffer, &buffersource->oBuffer, - kPortIndexInput, kPortIndexOutput)); + ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &buffersource->iBuffer, + &buffersource->oBuffer, kPortIndexInput, + kPortIndexOutput, portMode)); // test for callbacks EXPECT_EQ(buffersource->callback, 31); } @@ -1174,9 +1174,8 @@ TEST_P(VideoEncHidlTest, EncodeTest) { ASSERT_NO_FATAL_FAILURE( changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer)); // set state to executing - ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, - &oBuffer, kPortIndexInput, - kPortIndexOutput)); + ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, + kPortIndexInput, kPortIndexOutput, portMode)); } // test raw stream encode (input is ANW buffers) @@ -1337,9 +1336,8 @@ TEST_P(VideoEncHidlTest, EncodeTestBufferMetaModes) { changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer)); EXPECT_EQ(portDef.nBufferCountActual, listener->freeBuffers); // set state to executing - ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, - &oBuffer, kPortIndexInput, - kPortIndexOutput)); + ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, + kPortIndexInput, kPortIndexOutput, portMode)); returnval = producer->disconnect( NATIVE_WINDOW_API_CPU, IGraphicBufferProducer::DisconnectMode::API); @@ -1452,9 +1450,8 @@ TEST_P(VideoEncHidlTest, EncodeTestEOS) { changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer)); EXPECT_EQ(portDef.nBufferCountActual, listener->freeBuffers); // set state to executing - ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, - &oBuffer, kPortIndexInput, - kPortIndexOutput)); + ASSERT_NO_FATAL_FAILURE(changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer, + kPortIndexInput, kPortIndexOutput, portMode)); returnval = producer->disconnect( NATIVE_WINDOW_API_CPU, IGraphicBufferProducer::DisconnectMode::API);