Fix race condition in linearblock release between TIS and MediaCodec

Bug: 177247275
Test: Manual
Change-Id: I13f924adc3586607eb3a60d184e7786536c7b788
This commit is contained in:
Henry Fang
2021-01-11 12:27:49 -08:00
parent 73979a8847
commit 7bff9d579a

View File

@@ -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();
}