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

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

Merge "Fix race condition in linearblock release between TIS and MediaCodec"

parents 440937b4 7bff9d57
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -196,8 +196,9 @@ static fields_t gFields;
static int IP_V4_LENGTH = 4;
static int IP_V6_LENGTH = 16;

void DestroyCallback(const C2Buffer * /* buf */, void *arg) {
void DestroyCallback(const C2Buffer * buf, void *arg) {
    android::sp<android::MediaEvent> event = (android::MediaEvent *)arg;
    android::Mutex::Autolock autoLock(event->mLock);
    if (event->mLinearBlockObj != NULL) {
        JNIEnv *env = android::AndroidRuntime::getJNIEnv();
        env->DeleteWeakGlobalRef(event->mLinearBlockObj);
@@ -206,6 +207,7 @@ void DestroyCallback(const C2Buffer * /* buf */, void *arg) {

    event->mAvHandleRefCnt--;
    event->finalize();
    event->decStrong(buf);
}

namespace android {
@@ -408,6 +410,7 @@ jobject MediaEvent::getLinearBlock() {
            pC2Buffer->setInfo(info);
        }
        pC2Buffer->registerOnDestroyNotify(&DestroyCallback, this);
        incStrong(pC2Buffer.get());
        jobject linearBlock =
                env->NewObject(
                        env->FindClass("android/media/MediaCodec$LinearBlock"),
@@ -4411,6 +4414,7 @@ static jobject android_media_tv_Tuner_media_event_get_linear_block(
        ALOGD("Failed get MediaEvent");
        return NULL;
    }
    android::Mutex::Autolock autoLock(mediaEventSp->mLock);

    return mediaEventSp->getLinearBlock();
}