From 96743b42576bb508cd0820e9503a7d82003a682b Mon Sep 17 00:00:00 2001 From: Ram Mohan M Date: Wed, 9 Aug 2017 12:11:23 +0530 Subject: [PATCH] bug fix: configure input port buffer size In video decoders, size of a single input frame (elementary-stream) is dependent on width, height, color format, profile settings, ... Most of this information is part of sps, pps and requires parsing. But as the max size of the stream is known ahead, use it to configure the input buffer size requirements Bug: 63875287 Bug: 63796949 Change-Id: Ib760c4f55b094260a0abd120f852dcf1899df4e0 --- .../common/media_hidl_test_common.cpp | 19 +++++++++++ .../common/media_hidl_test_common.h | 6 ++++ .../VtsHalMediaOmxV1_0TargetVideoDecTest.cpp | 34 ++++++++++++++++--- 3 files changed, 55 insertions(+), 4 deletions(-) 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 863731aa2a..b7d53ed9b3 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 @@ -60,6 +60,25 @@ Return setRole( return setParam(omxNode, OMX_IndexParamStandardComponentRole, ¶ms); } +Return setPortBufferSize( + sp omxNode, OMX_U32 portIndex, OMX_U32 size) { + android::hardware::media::omx::V1_0::Status status; + OMX_PARAM_PORTDEFINITIONTYPE portDef; + + status = getPortParam(omxNode, OMX_IndexParamPortDefinition, portIndex, + &portDef); + if (status != ::android::hardware::media::omx::V1_0::Status::OK) + return status; + if (portDef.nBufferSize < size) { + portDef.nBufferSize = size; + status = setPortParam(omxNode, OMX_IndexParamPortDefinition, portIndex, + &portDef); + if (status != ::android::hardware::media::omx::V1_0::Status::OK) + return status; + } + return status; +} + // get/set video component port format Return setVideoPortFormat( sp omxNode, OMX_U32 portIndex, 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 29e6450ff6..d3ecc598c5 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 @@ -54,6 +54,9 @@ */ #define RANDOM_INDEX 1729 +#define ALIGN_POWER_OF_TWO(value, n) \ + (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1)) + enum bufferOwner { client, component, @@ -282,6 +285,9 @@ Return setPortConfig( Return setRole( sp omxNode, const char* role); +Return setPortBufferSize( + sp omxNode, OMX_U32 portIndex, OMX_U32 size); + Return setVideoPortFormat( sp omxNode, OMX_U32 portIndex, OMX_VIDEO_CODINGTYPE eCompressionFormat, OMX_COLOR_FORMATTYPE eColorFormat, 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 0771719c67..72777c40d0 100644 --- a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp +++ b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp @@ -897,7 +897,7 @@ TEST_F(VideoDecHidlTest, DecodeTest) { eleInfo.open(info); ASSERT_EQ(eleInfo.is_open(), true); android::Vector Info; - int bytesCount = 0; + int bytesCount = 0, maxBytesCount = 0; uint32_t flags = 0; uint32_t timestamp = 0; timestampDevTest = true; @@ -908,9 +908,15 @@ TEST_F(VideoDecHidlTest, DecodeTest) { Info.push_back({bytesCount, flags, timestamp}); if (flags != OMX_BUFFERFLAG_CODECCONFIG) timestampUslist.push_back(timestamp); + if (maxBytesCount < bytesCount) maxBytesCount = bytesCount; } eleInfo.close(); + // As the frame sizes are known ahead, use it to configure i/p buffer size + maxBytesCount = ALIGN_POWER_OF_TWO(maxBytesCount, 10); + status = setPortBufferSize(omxNode, kPortIndexInput, maxBytesCount); + ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); + // set port mode portMode[0] = PortMode::PRESET_BYTE_BUFFER; portMode[1] = PortMode::DYNAMIC_ANW_BUFFER; @@ -938,6 +944,8 @@ TEST_F(VideoDecHidlTest, DecodeTest) { EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); setDefaultPortParam(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused, eColorFormat, nFrameWidth, nFrameHeight, 0, xFramerate); + + // disabling adaptive playback. omxNode->prepareForAdaptivePlayback(kPortIndexOutput, false, 1920, 1080); android::Vector iBuffer, oBuffer; @@ -1067,7 +1075,7 @@ TEST_F(VideoDecHidlTest, ThumbnailTest) { eleInfo.open(info); ASSERT_EQ(eleInfo.is_open(), true); android::Vector Info; - int bytesCount = 0; + int bytesCount = 0, maxBytesCount = 0; uint32_t flags = 0; uint32_t timestamp = 0; while (1) { @@ -1075,9 +1083,15 @@ TEST_F(VideoDecHidlTest, ThumbnailTest) { eleInfo >> flags; eleInfo >> timestamp; Info.push_back({bytesCount, flags, timestamp}); + if (maxBytesCount < bytesCount) maxBytesCount = bytesCount; } eleInfo.close(); + // As the frame sizes are known ahead, use it to configure i/p buffer size + maxBytesCount = ALIGN_POWER_OF_TWO(maxBytesCount, 10); + status = setPortBufferSize(omxNode, kPortIndexInput, maxBytesCount); + ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); + // set port mode status = omxNode->setPortMode(kPortIndexInput, portMode[0]); ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); @@ -1174,7 +1188,7 @@ TEST_F(VideoDecHidlTest, SimpleEOSTest) { eleInfo.open(info); ASSERT_EQ(eleInfo.is_open(), true); android::Vector Info; - int bytesCount = 0; + int bytesCount = 0, maxBytesCount = 0; uint32_t flags = 0; uint32_t timestamp = 0; while (1) { @@ -1182,9 +1196,15 @@ TEST_F(VideoDecHidlTest, SimpleEOSTest) { eleInfo >> flags; eleInfo >> timestamp; Info.push_back({bytesCount, flags, timestamp}); + if (maxBytesCount < bytesCount) maxBytesCount = bytesCount; } eleInfo.close(); + // As the frame sizes are known ahead, use it to configure i/p buffer size + maxBytesCount = ALIGN_POWER_OF_TWO(maxBytesCount, 10); + status = setPortBufferSize(omxNode, kPortIndexInput, maxBytesCount); + ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); + // set port mode status = omxNode->setPortMode(kPortIndexInput, portMode[0]); ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); @@ -1263,7 +1283,7 @@ TEST_F(VideoDecHidlTest, FlushTest) { eleInfo.open(info); ASSERT_EQ(eleInfo.is_open(), true); android::Vector Info; - int bytesCount = 0; + int bytesCount = 0, maxBytesCount = 0; uint32_t flags = 0; uint32_t timestamp = 0; while (1) { @@ -1271,9 +1291,15 @@ TEST_F(VideoDecHidlTest, FlushTest) { eleInfo >> flags; eleInfo >> timestamp; Info.push_back({bytesCount, flags, timestamp}); + if (maxBytesCount < bytesCount) maxBytesCount = bytesCount; } eleInfo.close(); + // As the frame sizes are known ahead, use it to configure i/p buffer size + maxBytesCount = ALIGN_POWER_OF_TWO(maxBytesCount, 10); + status = setPortBufferSize(omxNode, kPortIndexInput, maxBytesCount); + ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK); + // set port mode status = omxNode->setPortMode(kPortIndexInput, portMode[0]); ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);