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

This commit is contained in:
TreeHugger Robot
2019-06-19 22:19:28 +00:00
committed by Android (Google) Code Review
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;