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

Commit 25419d27 authored by Wonsik Kim's avatar Wonsik Kim Committed by android-build-merger
Browse files

Merge "C2SoftAac: fix error handling" into pi-dev

am: 829d4349

Change-Id: Ib0f83179fa2f2bc81d9ee76cfba485297c7d31e8
parents 765c492f 829d4349
Loading
Loading
Loading
Loading
+44 −24
Original line number Diff line number Diff line
@@ -305,13 +305,31 @@ void C2SoftAac::drainRingBuffer(
        ALOGV("getting %d from ringbuffer", numSamples);

        std::shared_ptr<C2LinearBlock> block;
        C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE };
        std::function<void(const std::unique_ptr<C2Work>&)> fillWork =
            [&block, numSamples, pool, this]()
                    -> std::function<void(const std::unique_ptr<C2Work>&)> {
                auto fillEmptyWork = [](const std::unique_ptr<C2Work> &work, c2_status_t err) {
                    work->result = err;
                    work->worklets.front()->output.flags = work->input.flags;
                    work->worklets.front()->output.buffers.clear();
                    work->worklets.front()->output.ordinal = work->input.ordinal;
                    work->workletsProcessed = 1u;
                };

                using namespace std::placeholders;
                if (numSamples == 0) {
                    return std::bind(fillEmptyWork, _1, C2_OK);
                }

                // TODO: error handling, proper usage, etc.
        c2_status_t err = pool->fetchLinearBlock(numSamples * sizeof(int16_t), usage, &block);
                C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE };
                c2_status_t err = pool->fetchLinearBlock(
                        numSamples * sizeof(int16_t), usage, &block);
                if (err != C2_OK) {
            ALOGE("err = %d", err);
                    ALOGD("failed to fetch a linear block (%d)", err);
                    mSignalledError = true;
                    return std::bind(fillEmptyWork, _1, C2_NO_MEMORY);
                }

                C2WriteView wView = block->map().get();
                // TODO
                INT_PCM *outBuffer = reinterpret_cast<INT_PCM *>(wView.data());
@@ -319,23 +337,25 @@ void C2SoftAac::drainRingBuffer(
                if (ns != numSamples) {
                    ALOGE("not a complete frame of samples available");
                    mSignalledError = true;
            // TODO: notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
            return;
                    return std::bind(fillEmptyWork, _1, C2_CORRUPTED);
                }
        auto fillWork = [buffer = createLinearBuffer(block)](const std::unique_ptr<C2Work> &work) {
                return [buffer = createLinearBuffer(block)](const std::unique_ptr<C2Work> &work) {
                    work->result = C2_OK;
                    work->worklets.front()->output.flags = work->input.flags;
                    work->worklets.front()->output.buffers.clear();
                    work->worklets.front()->output.buffers.push_back(buffer);
                    work->worklets.front()->output.ordinal = work->input.ordinal;
                    work->workletsProcessed = 1u;
                };
            }();

        if (work && work->input.ordinal.frameIndex == c2_cntr64_t(outInfo.frameIndex)) {
            fillWork(work);
        } else {
            finish(outInfo.frameIndex, fillWork);
        }

        ALOGV("out timestamp %" PRIu64 " / %u", outInfo.timestamp, block->capacity());
        ALOGV("out timestamp %" PRIu64 " / %u", outInfo.timestamp, block ? block->capacity() : 0);
        mBuffersInfo.pop_front();
    }
}