Merge "media: keep JMediaCodec::mCodec reference until destruction" into qt-dev

am: 8a1174bc94

Change-Id: Ie53f380c5712f331d0345f33b621de26fb2975ce
This commit is contained in:
Wonsik Kim
2019-06-19 15:46:31 -07:00
committed by android-build-merger
2 changed files with 15 additions and 11 deletions

View File

@@ -211,21 +211,22 @@ void JMediaCodec::registerSelf() {
}
void JMediaCodec::release() {
if (mCodec != NULL) {
mCodec->release();
mCodec.clear();
mInitStatus = NO_INIT;
}
std::call_once(mReleaseFlag, [this] {
if (mCodec != NULL) {
mCodec->release();
mInitStatus = NO_INIT;
}
if (mLooper != NULL) {
mLooper->unregisterHandler(id());
mLooper->stop();
mLooper.clear();
}
if (mLooper != NULL) {
mLooper->unregisterHandler(id());
mLooper->stop();
mLooper.clear();
}
});
}
JMediaCodec::~JMediaCodec() {
if (mCodec != NULL || mLooper != NULL) {
if (mLooper != NULL) {
/* MediaCodec and looper should have been released explicitly already
* in setMediaCodec() (see comments in setMediaCodec()).
*

View File

@@ -17,6 +17,8 @@
#ifndef _ANDROID_MEDIA_MEDIACODEC_H_
#define _ANDROID_MEDIA_MEDIACODEC_H_
#include <mutex>
#include "jni.h"
#include <media/MediaAnalyticsItem.h>
@@ -156,6 +158,7 @@ private:
sp<ALooper> mLooper;
sp<MediaCodec> mCodec;
AString mNameAtCreation;
std::once_flag mReleaseFlag;
sp<AMessage> mCallbackNotification;
sp<AMessage> mOnFrameRenderedNotification;