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

Commit 603195bc authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "improve timeout handling"

parents 9a688972 df47955a
Loading
Loading
Loading
Loading
+16 −19
Original line number Diff line number Diff line
@@ -588,12 +588,12 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                            AudioDecHidlTest::standardComp comp) {
    android::hardware::media::omx::V1_0::Status status;
    Message msg;
    int timeOut = TIMEOUT_COUNTER;
    int timeOut = TIMEOUT_COUNTER_Q;

    while (timeOut--) {
        size_t i = 0;
        status =
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer);
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
        if (status == android::hardware::media::omx::V1_0::Status::OK) {
            EXPECT_EQ(msg.type, Message::Type::EVENT);
            packedArgs audioArgs = {eEncoding, comp};
@@ -613,8 +613,8 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
        size_t index;
        if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
            dispatchOutputBuffer(omxNode, oBuffer, index);
            timeOut = TIMEOUT_COUNTER_Q;
        }
        timeOut--;
    }
}

@@ -654,11 +654,12 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
        frameID++;
    }

    int timeOut = TIMEOUT_COUNTER;
    bool stall = false;
    int timeOut = TIMEOUT_COUNTER_Q;
    bool iQueued, oQueued;
    while (1) {
        iQueued = oQueued = false;
        status =
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer);
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);

        // Port Reconfiguration
        if (status == android::hardware::media::omx::V1_0::Status::OK &&
@@ -688,18 +689,16 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                                (*Info)[frameID].bytesCount, flags,
                                (*Info)[frameID].timestamp);
            frameID++;
            stall = false;
        } else
            stall = true;
            iQueued = true;
        }
        if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
            dispatchOutputBuffer(omxNode, oBuffer, index);
            stall = false;
        } else
            stall = true;
        if (stall)
            timeOut--;
            oQueued = true;
        }
        if (iQueued || oQueued)
            timeOut = TIMEOUT_COUNTER_Q;
        else
            timeOut = TIMEOUT_COUNTER;
            timeOut--;
        if (timeOut == 0) {
            EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite";
            break;
@@ -1149,9 +1148,8 @@ TEST_F(AudioDecHidlTest, FlushTest) {
    decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, eEncoding,
                  kPortIndexInput, kPortIndexOutput, eleStream, &Info, 0,
                  nFrames, compName, false);
    // Note: Assumes 200 ms is enough to end any decode call that started
    flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
               kPortIndexOutput, 200000);
               kPortIndexOutput);
    framesReceived = 0;

    // Seek to next key frame and start decoding till the end
@@ -1172,9 +1170,8 @@ TEST_F(AudioDecHidlTest, FlushTest) {
                      kPortIndexInput, kPortIndexOutput, eleStream, &Info,
                      index, Info.size() - index, compName, false);
    }
    // Note: Assumes 200 ms is enough to end any decode call that started
    flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
               kPortIndexOutput, 200000);
               kPortIndexOutput);
    framesReceived = 0;

    // set state to idle
+14 −15
Original line number Diff line number Diff line
@@ -342,12 +342,12 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                            android::Vector<BufferInfo>* oBuffer) {
    android::hardware::media::omx::V1_0::Status status;
    Message msg;
    int timeOut = TIMEOUT_COUNTER;
    int timeOut = TIMEOUT_COUNTER_Q;

    while (timeOut--) {
        size_t i = 0;
        status =
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer);
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
        EXPECT_EQ(status,
                  android::hardware::media::omx::V1_0::Status::TIMED_OUT);
        // status == TIMED_OUT, it could be due to process time being large
@@ -362,8 +362,8 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
        size_t index;
        if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
            dispatchOutputBuffer(omxNode, oBuffer, index);
            timeOut = TIMEOUT_COUNTER_Q;
        }
        timeOut--;
    }
}

@@ -400,11 +400,12 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
        nFrames--;
    }

    int timeOut = TIMEOUT_COUNTER;
    bool stall = false;
    int timeOut = TIMEOUT_COUNTER_Q;
    bool iQueued, oQueued;
    while (1) {
        iQueued = oQueued = false;
        status =
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer);
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);

        if (status == android::hardware::media::omx::V1_0::Status::OK)
            ASSERT_TRUE(false);
@@ -425,19 +426,17 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                                timestamp);
            timestamp += timestampIncr;
            nFrames--;
            stall = false;
        } else
            stall = true;
            iQueued = true;
        }
        // Dispatch output buffer
        if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
            dispatchOutputBuffer(omxNode, oBuffer, index);
            stall = false;
        } else
            stall = true;
        if (stall)
            timeOut--;
            oQueued = true;
        }
        if (iQueued || oQueued)
            timeOut = TIMEOUT_COUNTER_Q;
        else
            timeOut = TIMEOUT_COUNTER;
            timeOut--;
        if (timeOut == 0) {
            EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite";
            break;
+4 −4
Original line number Diff line number Diff line
@@ -532,7 +532,7 @@ void testEOS(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
        }
    }

    int timeOut = TIMEOUT_COUNTER;
    int timeOut = TIMEOUT_COUNTER_PE;
    while (timeOut--) {
        // Dispatch all client owned output buffers to recover remaining frames
        while (1) {
@@ -541,15 +541,15 @@ void testEOS(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                // if dispatch is successful, perhaps there is a latency
                // in the component. Dont be in a haste to leave. reset timeout
                // counter
                timeOut = TIMEOUT_COUNTER;
                timeOut = TIMEOUT_COUNTER_PE;
            } else {
                break;
            }
        }

        Message msg;
        status =
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer);
        status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_PE, iBuffer,
                                          oBuffer);
        if (status == android::hardware::media::omx::V1_0::Status::OK) {
            if (msg.data.eventData.event == OMX_EventPortSettingsChanged) {
                if (fptr) {
+16 −2
Original line number Diff line number Diff line
@@ -33,8 +33,21 @@
#include <media/openmax/OMX_AudioExt.h>
#include <media/openmax/OMX_VideoExt.h>

/* TIME OUTS (Wait time in dequeueMessage()) */

/* As component is switching states (loaded<->idle<->execute), dequeueMessage()
 * expects the events to be received within this duration */
#define DEFAULT_TIMEOUT 100000
#define TIMEOUT_COUNTER (10000000 / DEFAULT_TIMEOUT)
/* Time interval between successive Input/Output enqueues */
#define DEFAULT_TIMEOUT_Q 2000
/* While the component is amidst a process call, asynchronous commands like
 * flush, change states can get delayed (at max by process call time). Instead
 * of waiting on DEFAULT_TIMEOUT, we give an additional leeway. */
#define DEFAULT_TIMEOUT_PE 500000

/* Breakout Timeout :: 5 sec*/
#define TIMEOUT_COUNTER_Q (5000000 / DEFAULT_TIMEOUT_Q)
#define TIMEOUT_COUNTER_PE (5000000 / DEFAULT_TIMEOUT_PE)

/*
 * Random Index used for monkey testing while get/set parameters
@@ -310,7 +323,8 @@ void dispatchInputBuffer(sp<IOmxNode> omxNode,
void flushPorts(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                android::Vector<BufferInfo>* iBuffer,
                android::Vector<BufferInfo>* oBuffer, OMX_U32 kPortIndexInput,
                OMX_U32 kPortIndexOutput, int64_t timeoutUs = DEFAULT_TIMEOUT);
                OMX_U32 kPortIndexOutput,
                int64_t timeoutUs = DEFAULT_TIMEOUT_PE);

typedef void (*portreconfig)(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                             android::Vector<BufferInfo>* iBuffer,
+16 −19
Original line number Diff line number Diff line
@@ -604,12 +604,12 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                            PortMode oPortMode) {
    android::hardware::media::omx::V1_0::Status status;
    Message msg;
    int timeOut = TIMEOUT_COUNTER;
    int timeOut = TIMEOUT_COUNTER_Q;

    while (timeOut--) {
        size_t i = 0;
        status =
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer);
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
        if (status == android::hardware::media::omx::V1_0::Status::OK) {
            EXPECT_EQ(msg.type, Message::Type::EVENT);
            portReconfiguration(omxNode, observer, iBuffer, oBuffer,
@@ -628,8 +628,8 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
        size_t index;
        if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
            dispatchOutputBuffer(omxNode, oBuffer, index, oPortMode);
            timeOut = TIMEOUT_COUNTER_Q;
        }
        timeOut--;
    }
}

@@ -669,11 +669,12 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
        frameID++;
    }

    int timeOut = TIMEOUT_COUNTER;
    bool stall = false;
    int timeOut = TIMEOUT_COUNTER_Q;
    bool iQueued, oQueued;
    while (1) {
        iQueued = oQueued = false;
        status =
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer);
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);

        // Port Reconfiguration
        if (status == android::hardware::media::omx::V1_0::Status::OK &&
@@ -702,18 +703,16 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                                (*Info)[frameID].bytesCount, flags,
                                (*Info)[frameID].timestamp);
            frameID++;
            stall = false;
        } else
            stall = true;
            iQueued = true;
        }
        if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
            dispatchOutputBuffer(omxNode, oBuffer, index, oPortMode);
            stall = false;
        } else
            stall = true;
        if (stall)
            timeOut--;
            oQueued = true;
        }
        if (iQueued || oQueued)
            timeOut = TIMEOUT_COUNTER_Q;
        else
            timeOut = TIMEOUT_COUNTER;
            timeOut--;
        if (timeOut == 0) {
            EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite";
            break;
@@ -1165,9 +1164,8 @@ TEST_F(VideoDecHidlTest, FlushTest) {
    decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
                  kPortIndexOutput, eleStream, &Info, 0, nFrames, portMode[1],
                  false);
    // Note: Assumes 200 ms is enough to end any decode call that started
    flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
               kPortIndexOutput, 200000);
               kPortIndexOutput);
    framesReceived = 0;

    // Seek to next key frame and start decoding till the end
@@ -1188,9 +1186,8 @@ TEST_F(VideoDecHidlTest, FlushTest) {
                      kPortIndexOutput, eleStream, &Info, index,
                      Info.size() - index, portMode[1], false);
    }
    // Note: Assumes 200 ms is enough to end any decode call that started
    flushPorts(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
               kPortIndexOutput, 200000);
               kPortIndexOutput);
    framesReceived = 0;

    // set state to idle
Loading