Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 96743b42 authored by Ram Mohan M's avatar Ram Mohan M Committed by Pawin Vongmasa
Browse files

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
parent b417e4c6
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -60,6 +60,25 @@ Return<android::hardware::media::omx::V1_0::Status> setRole(
    return setParam(omxNode, OMX_IndexParamStandardComponentRole, &params);
}

Return<android::hardware::media::omx::V1_0::Status> setPortBufferSize(
    sp<IOmxNode> 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<android::hardware::media::omx::V1_0::Status> setVideoPortFormat(
    sp<IOmxNode> omxNode, OMX_U32 portIndex,
+6 −0
Original line number Diff line number Diff line
@@ -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<android::hardware::media::omx::V1_0::Status> setPortConfig(
Return<android::hardware::media::omx::V1_0::Status> setRole(
    sp<IOmxNode> omxNode, const char* role);

Return<android::hardware::media::omx::V1_0::Status> setPortBufferSize(
    sp<IOmxNode> omxNode, OMX_U32 portIndex, OMX_U32 size);

Return<android::hardware::media::omx::V1_0::Status> setVideoPortFormat(
    sp<IOmxNode> omxNode, OMX_U32 portIndex,
    OMX_VIDEO_CODINGTYPE eCompressionFormat, OMX_COLOR_FORMATTYPE eColorFormat,
+30 −4
Original line number Diff line number Diff line
@@ -897,7 +897,7 @@ TEST_F(VideoDecHidlTest, DecodeTest) {
    eleInfo.open(info);
    ASSERT_EQ(eleInfo.is_open(), true);
    android::Vector<FrameData> 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<BufferInfo> iBuffer, oBuffer;
@@ -1067,7 +1075,7 @@ TEST_F(VideoDecHidlTest, ThumbnailTest) {
    eleInfo.open(info);
    ASSERT_EQ(eleInfo.is_open(), true);
    android::Vector<FrameData> 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<FrameData> 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<FrameData> 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);