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

Commit 215a490e authored by Wei Jia's avatar Wei Jia Committed by android-build-merger
Browse files

Merge "NuPlayerDecoder: check mCodec before dereferencing" into oc-mr1-dev

am: 298346c3

Change-Id: I4f4b42c21aa957132d3ca58d975c10a56c6a5c9c
parents 813ab342 298346c3
Loading
Loading
Loading
Loading
+36 −8
Original line number Original line Diff line number Diff line
@@ -343,7 +343,7 @@ void NuPlayer::Decoder::onConfigure(const sp<AMessage> &format) {
            format, mSurface, crypto, 0 /* flags */);
            format, mSurface, crypto, 0 /* flags */);


    if (err != OK) {
    if (err != OK) {
        ALOGE("Failed to configure %s decoder (err=%d)", mComponentName.c_str(), err);
        ALOGE("Failed to configure [%s] decoder (err=%d)", mComponentName.c_str(), err);
        mCodec->release();
        mCodec->release();
        mCodec.clear();
        mCodec.clear();
        handleError(err);
        handleError(err);
@@ -372,7 +372,7 @@ void NuPlayer::Decoder::onConfigure(const sp<AMessage> &format) {


    err = mCodec->start();
    err = mCodec->start();
    if (err != OK) {
    if (err != OK) {
        ALOGE("Failed to start %s decoder (err=%d)", mComponentName.c_str(), err);
        ALOGE("Failed to start [%s] decoder (err=%d)", mComponentName.c_str(), err);
        mCodec->release();
        mCodec->release();
        mCodec.clear();
        mCodec.clear();
        handleError(err);
        handleError(err);
@@ -460,6 +460,12 @@ void NuPlayer::Decoder::onResume(bool notifyComplete) {
    if (notifyComplete) {
    if (notifyComplete) {
        mResumePending = true;
        mResumePending = true;
    }
    }

    if (mCodec == NULL) {
        ALOGE("[%s] onResume without a valid codec", mComponentName.c_str());
        handleError(NO_INIT);
        return;
    }
    mCodec->start();
    mCodec->start();
}
}


@@ -481,7 +487,7 @@ void NuPlayer::Decoder::doFlush(bool notifyComplete) {
    }
    }


    if (err != OK) {
    if (err != OK) {
        ALOGE("failed to flush %s (err=%d)", mComponentName.c_str(), err);
        ALOGE("failed to flush [%s] (err=%d)", mComponentName.c_str(), err);
        handleError(err);
        handleError(err);
        // finish with posting kWhatFlushCompleted.
        // finish with posting kWhatFlushCompleted.
        // we attempt to release the buffers even if flush fails.
        // we attempt to release the buffers even if flush fails.
@@ -530,7 +536,7 @@ void NuPlayer::Decoder::onShutdown(bool notifyComplete) {
    releaseAndResetMediaBuffers();
    releaseAndResetMediaBuffers();


    if (err != OK) {
    if (err != OK) {
        ALOGE("failed to release %s (err=%d)", mComponentName.c_str(), err);
        ALOGE("failed to release [%s] (err=%d)", mComponentName.c_str(), err);
        handleError(err);
        handleError(err);
        // finish with posting kWhatShutdownCompleted.
        // finish with posting kWhatShutdownCompleted.
    }
    }
@@ -631,10 +637,17 @@ bool NuPlayer::Decoder::handleAnInputBuffer(size_t index) {
        return false;
        return false;
    }
    }


    if (mCodec == NULL) {
        ALOGE("[%s] handleAnInputBuffer without a valid codec", mComponentName.c_str());
        handleError(NO_INIT);
        return false;
    }

    sp<MediaCodecBuffer> buffer;
    sp<MediaCodecBuffer> buffer;
    mCodec->getInputBuffer(index, &buffer);
    mCodec->getInputBuffer(index, &buffer);


    if (buffer == NULL) {
    if (buffer == NULL) {
        ALOGE("[%s] handleAnInputBuffer, failed to get input buffer", mComponentName.c_str());
        handleError(UNKNOWN_ERROR);
        handleError(UNKNOWN_ERROR);
        return false;
        return false;
    }
    }
@@ -697,11 +710,18 @@ bool NuPlayer::Decoder::handleAnOutputBuffer(
        size_t size,
        size_t size,
        int64_t timeUs,
        int64_t timeUs,
        int32_t flags) {
        int32_t flags) {
    if (mCodec == NULL) {
        ALOGE("[%s] handleAnOutputBuffer without a valid codec", mComponentName.c_str());
        handleError(NO_INIT);
        return false;
    }

//    CHECK_LT(bufferIx, mOutputBuffers.size());
//    CHECK_LT(bufferIx, mOutputBuffers.size());
    sp<MediaCodecBuffer> buffer;
    sp<MediaCodecBuffer> buffer;
    mCodec->getOutputBuffer(index, &buffer);
    mCodec->getOutputBuffer(index, &buffer);


    if (buffer == NULL) {
    if (buffer == NULL) {
        ALOGE("[%s] handleAnOutputBuffer, failed to get output buffer", mComponentName.c_str());
        handleError(UNKNOWN_ERROR);
        handleError(UNKNOWN_ERROR);
        return false;
        return false;
    }
    }
@@ -949,6 +969,12 @@ status_t NuPlayer::Decoder::fetchInputData(sp<AMessage> &reply) {
}
}


bool NuPlayer::Decoder::onInputBufferFetched(const sp<AMessage> &msg) {
bool NuPlayer::Decoder::onInputBufferFetched(const sp<AMessage> &msg) {
    if (mCodec == NULL) {
        ALOGE("[%s] onInputBufferFetched without a valid codec", mComponentName.c_str());
        handleError(NO_INIT);
        return false;
    }

    size_t bufferIx;
    size_t bufferIx;
    CHECK(msg->findSize("buffer-ix", &bufferIx));
    CHECK(msg->findSize("buffer-ix", &bufferIx));
    CHECK_LT(bufferIx, mInputBuffers.size());
    CHECK_LT(bufferIx, mInputBuffers.size());
@@ -979,7 +1005,7 @@ bool NuPlayer::Decoder::onInputBufferFetched(const sp<AMessage> &msg) {
        }
        }


        if (streamErr != ERROR_END_OF_STREAM) {
        if (streamErr != ERROR_END_OF_STREAM) {
            ALOGE("Stream error for %s (err=%d), EOS %s queued",
            ALOGE("Stream error for [%s] (err=%d), EOS %s queued",
                    mComponentName.c_str(),
                    mComponentName.c_str(),
                    streamErr,
                    streamErr,
                    err == OK ? "successfully" : "unsuccessfully");
                    err == OK ? "successfully" : "unsuccessfully");
@@ -1073,7 +1099,7 @@ bool NuPlayer::Decoder::onInputBufferFetched(const sp<AMessage> &msg) {
        } // no cryptInfo
        } // no cryptInfo


        if (err != OK) {
        if (err != OK) {
            ALOGE("onInputBufferFetched: queue%sInputBuffer failed for %s (err=%d, %s)",
            ALOGE("onInputBufferFetched: queue%sInputBuffer failed for [%s] (err=%d, %s)",
                    (cryptInfo != NULL ? "Secure" : ""),
                    (cryptInfo != NULL ? "Secure" : ""),
                    mComponentName.c_str(), err, errorDetailMsg.c_str());
                    mComponentName.c_str(), err, errorDetailMsg.c_str());
            handleError(err);
            handleError(err);
@@ -1102,7 +1128,9 @@ void NuPlayer::Decoder::onRenderBuffer(const sp<AMessage> &msg) {
        }
        }
    }
    }


    if (msg->findInt32("render", &render) && render) {
    if (mCodec == NULL) {
        err = NO_INIT;
    } else if (msg->findInt32("render", &render) && render) {
        int64_t timestampNs;
        int64_t timestampNs;
        CHECK(msg->findInt64("timestampNs", &timestampNs));
        CHECK(msg->findInt64("timestampNs", &timestampNs));
        err = mCodec->renderOutputBufferAndRelease(bufferIx, timestampNs);
        err = mCodec->renderOutputBufferAndRelease(bufferIx, timestampNs);
@@ -1111,7 +1139,7 @@ void NuPlayer::Decoder::onRenderBuffer(const sp<AMessage> &msg) {
        err = mCodec->releaseOutputBuffer(bufferIx);
        err = mCodec->releaseOutputBuffer(bufferIx);
    }
    }
    if (err != OK) {
    if (err != OK) {
        ALOGE("failed to release output buffer for %s (err=%d)",
        ALOGE("failed to release output buffer for [%s] (err=%d)",
                mComponentName.c_str(), err);
                mComponentName.c_str(), err);
        handleError(err);
        handleError(err);
    }
    }