Merge "Fix MediaEvent release issue" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c266b0398e
@@ -29,6 +29,7 @@ import android.media.MediaCodec.LinearBlock;
|
|||||||
@SystemApi
|
@SystemApi
|
||||||
public class MediaEvent extends FilterEvent {
|
public class MediaEvent extends FilterEvent {
|
||||||
private long mNativeContext;
|
private long mNativeContext;
|
||||||
|
private boolean mReleased = false;
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
|
|
||||||
private native Long nativeGetAudioHandle();
|
private native Long nativeGetAudioHandle();
|
||||||
@@ -181,7 +182,21 @@ public class MediaEvent extends FilterEvent {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() {
|
protected void finalize() {
|
||||||
nativeFinalize();
|
release();
|
||||||
mNativeContext = 0;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases the MediaEvent object.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void release() {
|
||||||
|
synchronized (mLock) {
|
||||||
|
if (mReleased) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nativeFinalize();
|
||||||
|
mNativeContext = 0;
|
||||||
|
mReleased = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -314,8 +314,9 @@ MediaEvent::~MediaEvent() {
|
|||||||
if (mIonHandle != NULL) {
|
if (mIonHandle != NULL) {
|
||||||
delete mIonHandle;
|
delete mIonHandle;
|
||||||
}
|
}
|
||||||
if (mC2Buffer != NULL) {
|
std::shared_ptr<C2Buffer> pC2Buffer = mC2Buffer.lock();
|
||||||
mC2Buffer->unregisterOnDestroyNotify(&DestroyCallback, this);
|
if (pC2Buffer != NULL) {
|
||||||
|
pC2Buffer->unregisterOnDestroyNotify(&DestroyCallback, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,15 +341,17 @@ jobject MediaEvent::getLinearBlock() {
|
|||||||
JNIEnv *env = AndroidRuntime::getJNIEnv();
|
JNIEnv *env = AndroidRuntime::getJNIEnv();
|
||||||
std::unique_ptr<JMediaCodecLinearBlock> context{new JMediaCodecLinearBlock};
|
std::unique_ptr<JMediaCodecLinearBlock> context{new JMediaCodecLinearBlock};
|
||||||
context->mBlock = block;
|
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) {
|
if (mAvHandle->numInts > 0) {
|
||||||
// use first int in the native_handle as the index
|
// use first int in the native_handle as the index
|
||||||
int index = mAvHandle->data[mAvHandle->numFds];
|
int index = mAvHandle->data[mAvHandle->numFds];
|
||||||
std::shared_ptr<C2Param> c2param = std::make_shared<C2DataIdInfo>(index, mDataId);
|
std::shared_ptr<C2Param> c2param = std::make_shared<C2DataIdInfo>(index, mDataId);
|
||||||
std::shared_ptr<C2Info> info(std::static_pointer_cast<C2Info>(c2param));
|
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 =
|
jobject linearBlock =
|
||||||
env->NewObject(
|
env->NewObject(
|
||||||
env->FindClass("android/media/MediaCodec$LinearBlock"),
|
env->FindClass("android/media/MediaCodec$LinearBlock"),
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ struct MediaEvent : public RefBase {
|
|||||||
jweak mMediaEventObj;
|
jweak mMediaEventObj;
|
||||||
jweak mLinearBlockObj;
|
jweak mLinearBlockObj;
|
||||||
C2HandleIon* mIonHandle;
|
C2HandleIon* mIonHandle;
|
||||||
std::shared_ptr<C2Buffer> mC2Buffer;
|
std::weak_ptr<C2Buffer> mC2Buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Filter : public RefBase {
|
struct Filter : public RefBase {
|
||||||
|
|||||||
Reference in New Issue
Block a user