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

Commit 1fc35e65 authored by Henry Fang's avatar Henry Fang
Browse files

Fix issue which Ion handle are free twice.

bug: 162083545
Test: Manual
Change-Id: I3a53fe949ecfdff4614a44cc1ddecdbeaa583dd8
Merged-In: I3a53fe949ecfdff4614a44cc1ddecdbeaa583dd8
parent eec09803
Loading
Loading
Loading
Loading
+38 −27
Original line number Diff line number Diff line
@@ -337,7 +337,10 @@ jobject MediaEvent::getLinearBlock() {
    }
    mIonHandle = new C2HandleIon(dup(mAvHandle->data[0]), mDataLength);
    std::shared_ptr<C2LinearBlock> block = _C2BlockFactory::CreateLinearBlock(mIonHandle);

    if (block != nullptr) {
        // CreateLinearBlock delete mIonHandle after it create block successfully.
        // ToDo: coordinate who is response to delete mIonHandle
        mIonHandle = NULL;
        JNIEnv *env = AndroidRuntime::getJNIEnv();
        std::unique_ptr<JMediaCodecLinearBlock> context{new JMediaCodecLinearBlock};
        context->mBlock = block;
@@ -364,6 +367,14 @@ jobject MediaEvent::getLinearBlock() {
        mLinearBlockObj = env->NewWeakGlobalRef(linearBlock);
        mAvHandleRefCnt++;
        return mLinearBlockObj;
    } else {
        native_handle_close(const_cast<native_handle_t*>(
                    reinterpret_cast<const native_handle_t*>(mIonHandle)));
        native_handle_delete(const_cast<native_handle_t*>(
                    reinterpret_cast<const native_handle_t*>(mIonHandle)));
        mIonHandle = NULL;
        return NULL;
    }
}

uint64_t MediaEvent::getAudioHandle() {