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

Commit 2211efaf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix MediaEvent release issue" into rvc-dev am: c266b039

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11897358

Change-Id: I11a954465b116b38339280a213c5632f2f739c1a
parents c109cecd c266b039
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.media.MediaCodec.LinearBlock;
@SystemApi
public class MediaEvent extends FilterEvent {
    private long mNativeContext;
    private boolean mReleased = false;
    private final Object mLock = new Object();

    private native Long nativeGetAudioHandle();
@@ -181,7 +182,21 @@ public class MediaEvent extends FilterEvent {
     */
    @Override
    protected void finalize() {
        release();
    }

    /**
     * Releases the MediaEvent object.
     * @hide
     */
    public void release() {
        synchronized (mLock) {
            if (mReleased) {
                return;
            }
            nativeFinalize();
            mNativeContext = 0;
            mReleased = true;
        }
    }
}
+8 −5
Original line number Diff line number Diff line
@@ -314,8 +314,9 @@ MediaEvent::~MediaEvent() {
    if (mIonHandle != NULL) {
        delete mIonHandle;
    }
    if (mC2Buffer != NULL) {
        mC2Buffer->unregisterOnDestroyNotify(&DestroyCallback, this);
    std::shared_ptr<C2Buffer> pC2Buffer = mC2Buffer.lock();
    if (pC2Buffer != NULL) {
        pC2Buffer->unregisterOnDestroyNotify(&DestroyCallback, this);
    }
}

@@ -340,15 +341,17 @@ jobject MediaEvent::getLinearBlock() {
    JNIEnv *env = AndroidRuntime::getJNIEnv();
    std::unique_ptr<JMediaCodecLinearBlock> context{new JMediaCodecLinearBlock};
    context->mBlock = block;
    mC2Buffer = context->toC2Buffer(0, mDataLength);
    std::shared_ptr<C2Buffer> pC2Buffer = context->toC2Buffer(0, mDataLength);
    context->mBuffer = pC2Buffer;
    mC2Buffer = pC2Buffer;
    if (mAvHandle->numInts > 0) {
        // use first int in the native_handle as the index
        int index = mAvHandle->data[mAvHandle->numFds];
        std::shared_ptr<C2Param> c2param = std::make_shared<C2DataIdInfo>(index, mDataId);
        std::shared_ptr<C2Info> info(std::static_pointer_cast<C2Info>(c2param));
        mC2Buffer->setInfo(info);
        pC2Buffer->setInfo(info);
    }
    mC2Buffer->registerOnDestroyNotify(&DestroyCallback, this);
    pC2Buffer->registerOnDestroyNotify(&DestroyCallback, this);
    jobject linearBlock =
            env->NewObject(
                    env->FindClass("android/media/MediaCodec$LinearBlock"),
+1 −1
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ struct MediaEvent : public RefBase {
    jweak mMediaEventObj;
    jweak mLinearBlockObj;
    C2HandleIon* mIonHandle;
    std::shared_ptr<C2Buffer> mC2Buffer;
    std::weak_ptr<C2Buffer> mC2Buffer;
};

struct Filter : public RefBase {