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

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

Merge "Signal eof flag for each input buffer" into oc-mr1-dev

parents 5f03369e 0cf6b3df
Loading
Loading
Loading
Loading
+9 −26
Original line number Diff line number Diff line
@@ -643,39 +643,16 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                   AudioDecHidlTest::standardComp comp, bool signalEOS = true) {
    android::hardware::media::omx::V1_0::Status status;
    Message msg;

    // dispatch output buffers
    for (size_t i = 0; i < oBuffer->size(); i++) {
        dispatchOutputBuffer(omxNode, oBuffer, i);
    }
    // dispatch input buffers
    size_t index;
    uint32_t flags = 0;
    int frameID = offset;
    for (size_t i = 0; (i < iBuffer->size()) && (frameID < (int)Info->size()) &&
                       (frameID < (offset + range));
         i++) {
        char* ipBuffer = static_cast<char*>(
            static_cast<void*>((*iBuffer)[i].mMemory->getPointer()));
        ASSERT_LE((*Info)[frameID].bytesCount,
                  static_cast<int>((*iBuffer)[i].mMemory->getSize()));
        eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
        ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
        flags = (*Info)[frameID].flags;
        if (signalEOS && ((frameID == (int)Info->size() - 1) ||
                          (frameID == (offset + range - 1))))
            flags |= OMX_BUFFERFLAG_EOS;
        dispatchInputBuffer(omxNode, iBuffer, i, (*Info)[frameID].bytesCount,
                            flags, (*Info)[frameID].timestamp);
        frameID++;
    }

    int timeOut = TIMEOUT_COUNTER_Q;
    bool iQueued, oQueued;

    while (1) {
        iQueued = oQueued = false;
        status =
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);

        // Port Reconfiguration
        if (status == android::hardware::media::omx::V1_0::Status::OK &&
            msg.type == Message::Type::EVENT) {
@@ -688,7 +665,6 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
        if (frameID == (int)Info->size() || frameID == (offset + range)) break;

        // Dispatch input buffer
        size_t index = 0;
        if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
            char* ipBuffer = static_cast<char*>(
                static_cast<void*>((*iBuffer)[index].mMemory->getPointer()));
@@ -697,6 +673,11 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
            eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
            ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
            flags = (*Info)[frameID].flags;
            // Indicate to omx core that the buffer contains a full frame worth
            // of data
            flags |= OMX_BUFFERFLAG_ENDOFFRAME;
            // Indicate the omx core that this is the last buffer it needs to
            // process
            if (signalEOS && ((frameID == (int)Info->size() - 1) ||
                              (frameID == (offset + range - 1))))
                flags |= OMX_BUFFERFLAG_EOS;
@@ -706,10 +687,12 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
            frameID++;
            iQueued = true;
        }
        // Dispatch output buffer
        if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
            dispatchOutputBuffer(omxNode, oBuffer, index);
            oQueued = true;
        }
        // Reset Counters when either input or output buffer is dispatched
        if (iQueued || oQueued)
            timeOut = TIMEOUT_COUNTER_Q;
        else
+5 −22
Original line number Diff line number Diff line
@@ -376,44 +376,25 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                   bool signalEOS = true) {
    android::hardware::media::omx::V1_0::Status status;
    Message msg;

    // dispatch output buffers
    for (size_t i = 0; i < oBuffer->size(); i++) {
        dispatchOutputBuffer(omxNode, oBuffer, i);
    }
    // dispatch input buffers
    size_t index;
    int bytesCount = samplesPerFrame * nChannels * 2;
    int32_t timestampIncr =
        (int)(((float)samplesPerFrame / nSampleRate) * 1000000);
    uint64_t timestamp = 0;
    uint32_t flags = 0;
    for (size_t i = 0; i < iBuffer->size() && nFrames != 0; i++) {
        char* ipBuffer = static_cast<char*>(
            static_cast<void*>((*iBuffer)[i].mMemory->getPointer()));
        ASSERT_LE(bytesCount,
                  static_cast<int>((*iBuffer)[i].mMemory->getSize()));
        eleStream.read(ipBuffer, bytesCount);
        if (eleStream.gcount() != bytesCount) break;
        if (signalEOS && (nFrames == 1)) flags = OMX_BUFFERFLAG_EOS;
        dispatchInputBuffer(omxNode, iBuffer, i, bytesCount, flags, timestamp);
        timestamp += timestampIncr;
        nFrames--;
    }

    int timeOut = TIMEOUT_COUNTER_Q;
    bool iQueued, oQueued;

    while (1) {
        iQueued = oQueued = false;
        status =
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);

        if (status == android::hardware::media::omx::V1_0::Status::OK)
            ASSERT_TRUE(false);

        if (nFrames == 0) break;

        // Dispatch input buffer
        size_t index = 0;
        if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
            char* ipBuffer = static_cast<char*>(
                static_cast<void*>((*iBuffer)[index].mMemory->getPointer()));
@@ -421,7 +402,8 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                      static_cast<int>((*iBuffer)[index].mMemory->getSize()));
            eleStream.read(ipBuffer, bytesCount);
            if (eleStream.gcount() != bytesCount) break;
            if (signalEOS && (nFrames == 1)) flags = OMX_BUFFERFLAG_EOS;
            flags = OMX_BUFFERFLAG_ENDOFFRAME;
            if (signalEOS && (nFrames == 1)) flags |= OMX_BUFFERFLAG_EOS;
            dispatchInputBuffer(omxNode, iBuffer, index, bytesCount, flags,
                                timestamp);
            timestamp += timestampIncr;
@@ -433,6 +415,7 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
            dispatchOutputBuffer(omxNode, oBuffer, index);
            oQueued = true;
        }
        // Reset Counters when either input or output buffer is dispatched
        if (iQueued || oQueued)
            timeOut = TIMEOUT_COUNTER_Q;
        else
+9 −26
Original line number Diff line number Diff line
@@ -601,39 +601,16 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                   bool signalEOS = true) {
    android::hardware::media::omx::V1_0::Status status;
    Message msg;

    // dispatch output buffers
    for (size_t i = 0; i < oBuffer->size(); i++) {
        dispatchOutputBuffer(omxNode, oBuffer, i, oPortMode);
    }
    // dispatch input buffers
    size_t index;
    uint32_t flags = 0;
    int frameID = offset;
    for (size_t i = 0; (i < iBuffer->size()) && (frameID < (int)Info->size()) &&
                       (frameID < (offset + range));
         i++) {
        char* ipBuffer = static_cast<char*>(
            static_cast<void*>((*iBuffer)[i].mMemory->getPointer()));
        ASSERT_LE((*Info)[frameID].bytesCount,
                  static_cast<int>((*iBuffer)[i].mMemory->getSize()));
        eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
        ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
        flags = (*Info)[frameID].flags;
        if (signalEOS && ((frameID == (int)Info->size() - 1) ||
                          (frameID == (offset + range - 1))))
            flags |= OMX_BUFFERFLAG_EOS;
        dispatchInputBuffer(omxNode, iBuffer, i, (*Info)[frameID].bytesCount,
                            flags, (*Info)[frameID].timestamp);
        frameID++;
    }

    int timeOut = TIMEOUT_COUNTER_Q;
    bool iQueued, oQueued;

    while (1) {
        iQueued = oQueued = false;
        status =
            observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);

        // Port Reconfiguration
        if (status == android::hardware::media::omx::V1_0::Status::OK &&
            msg.type == Message::Type::EVENT) {
@@ -645,7 +622,6 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
        if (frameID == (int)Info->size() || frameID == (offset + range)) break;

        // Dispatch input buffer
        size_t index = 0;
        if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
            char* ipBuffer = static_cast<char*>(
                static_cast<void*>((*iBuffer)[index].mMemory->getPointer()));
@@ -654,6 +630,11 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
            eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
            ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
            flags = (*Info)[frameID].flags;
            // Indicate to omx core that the buffer contains a full frame worth
            // of data
            flags |= OMX_BUFFERFLAG_ENDOFFRAME;
            // Indicate the omx core that this is the last buffer it needs to
            // process
            if (signalEOS && ((frameID == (int)Info->size() - 1) ||
                              (frameID == (offset + range - 1))))
                flags |= OMX_BUFFERFLAG_EOS;
@@ -663,10 +644,12 @@ void decodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
            frameID++;
            iQueued = true;
        }
        // Dispatch output buffer
        if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
            dispatchOutputBuffer(omxNode, oBuffer, index, oPortMode);
            oQueued = true;
        }
        // Reset Counters when either input or output buffer is dispatched
        if (iQueued || oQueued)
            timeOut = TIMEOUT_COUNTER_Q;
        else
+12 −41
Original line number Diff line number Diff line
@@ -983,58 +983,25 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                   sp<CodecProducerListener> listener = nullptr) {
    android::hardware::media::omx::V1_0::Status status;
    Message msg;
    uint32_t ipCount = 0;
    uint64_t timestamp = 0;
    uint32_t flags = 0;
    int timeOut = TIMEOUT_COUNTER_Q;
    bool iQueued, oQueued;

    uint32_t ipCount = 0;
    if (ipCount == 0) {
        status = changeFrameRate(omxNode, portIndexOutput, (24U << 16));
        if (status == ::android::hardware::media::omx::V1_0::Status::OK)
            xFramerate = (24U << 16);
    }

    // dispatch output buffers
    for (size_t i = 0; i < oBuffer->size(); i++) {
        dispatchOutputBuffer(omxNode, oBuffer, i);
    }
    // dispatch input buffers
    int32_t timestampIncr = (int)((float)1000000 / (xFramerate >> 16));
    // timestamp scale = Nano sec
    if (inputDataIsMeta) timestampIncr *= 1000;
    uint64_t timestamp = 0;
    uint32_t flags = 0;
    for (size_t i = 0; i < iBuffer->size() && nFrames != 0; i++) {
        if (inputDataIsMeta) {
            if (listener->freeBuffers > listener->minUnDequeuedCount) {
                if (dispatchGraphicBuffer(omxNode, producer, listener, iBuffer,
                                          portIndexInput, eleStream, timestamp))
                    break;
                timestamp += timestampIncr;
                nFrames--;
                ipCount++;
            }
        } else {
            char* ipBuffer = static_cast<char*>(
                static_cast<void*>((*iBuffer)[i].mMemory->getPointer()));
            ASSERT_LE(bytesCount,
                      static_cast<int>((*iBuffer)[i].mMemory->getSize()));
            if (fillByteBuffer(omxNode, ipBuffer, portIndexInput, eleStream))
                break;
            if (signalEOS && (nFrames == 1)) flags = OMX_BUFFERFLAG_EOS;
            dispatchInputBuffer(omxNode, iBuffer, i, bytesCount, flags,
                                timestamp);
            if (timestampUslist) timestampUslist->push_back(timestamp);
            timestamp += timestampIncr;
            nFrames--;
            ipCount++;
        }
    }
    if (inputDataIsMeta) timestampIncr *= 1000;  // timestamp scale: Nano sec

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

        // Port Reconfiguration
        if (status == android::hardware::media::omx::V1_0::Status::OK) {
            ASSERT_EQ(msg.type, Message::Type::EVENT);
            if (msg.data.eventData.event == OMX_EventPortSettingsChanged) {
@@ -1076,7 +1043,8 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                if (fillByteBuffer(omxNode, ipBuffer, portIndexInput,
                                   eleStream))
                    break;
                if (signalEOS && (nFrames == 1)) flags = OMX_BUFFERFLAG_EOS;
                flags = OMX_BUFFERFLAG_ENDOFFRAME;
                if (signalEOS && (nFrames == 1)) flags |= OMX_BUFFERFLAG_EOS;
                dispatchInputBuffer(omxNode, iBuffer, index, bytesCount, flags,
                                    timestamp);
                if (timestampUslist) timestampUslist->push_back(timestamp);
@@ -1086,10 +1054,12 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                iQueued = true;
            }
        }
        // Dispatch output buffer
        if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
            dispatchOutputBuffer(omxNode, oBuffer, index);
            oQueued = true;
        }
        // Reset Counters when either input or output buffer is dispatched
        if (iQueued || oQueued)
            timeOut = TIMEOUT_COUNTER_Q;
        else
@@ -1098,6 +1068,7 @@ void encodeNFrames(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
            EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite";
            break;
        }
        // Runtime Param Configuration
        if (ipCount == 15) {
            changeBitrate(omxNode, portIndexOutput, 768000);
            requestIDR(omxNode, portIndexOutput);