summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Hung <hunga@google.com>2015-04-30 00:44:20 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-04-30 00:44:21 +0000
commitc0239eca6d022b498d21cc467f83f715f7e7ed89 (patch)
treeaffbeca1efa1828af1d67af8f5c2c681be3a53e4
parent7b21efcf733b59ea317fc6dba267c79ac1ed5d5d (diff)
parent6bb63addf65905dcc4d5f0461559142a716f6fbb (diff)
downloadframeworks_av-c0239eca6d022b498d21cc467f83f715f7e7ed89.zip
frameworks_av-c0239eca6d022b498d21cc467f83f715f7e7ed89.tar.gz
frameworks_av-c0239eca6d022b498d21cc467f83f715f7e7ed89.tar.bz2
Merge "NdkMediaCodec: Return NULL if the MediaCodec cannot be created" into mnc-dev
-rw-r--r--media/ndk/NdkMediaCodec.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/media/ndk/NdkMediaCodec.cpp b/media/ndk/NdkMediaCodec.cpp
index 80c1c2f..cd0c462 100644
--- a/media/ndk/NdkMediaCodec.cpp
+++ b/media/ndk/NdkMediaCodec.cpp
@@ -154,6 +154,10 @@ static AMediaCodec * createAMediaCodec(const char *name, bool name_is_type, bool
} else {
mData->mCodec = android::MediaCodec::CreateByComponentName(mData->mLooper, name);
}
+ if (mData->mCodec == NULL) { // failed to create codec
+ AMediaCodec_delete(mData);
+ return NULL;
+ }
mData->mHandler = new CodecHandler(mData);
mData->mLooper->registerHandler(mData->mHandler);
mData->mGeneration = 1;
@@ -180,17 +184,21 @@ AMediaCodec* AMediaCodec_createEncoderByType(const char *name) {
EXPORT
media_status_t AMediaCodec_delete(AMediaCodec *mData) {
- if (mData->mCodec != NULL) {
- mData->mCodec->release();
- mData->mCodec.clear();
- }
+ if (mData != NULL) {
+ if (mData->mCodec != NULL) {
+ mData->mCodec->release();
+ mData->mCodec.clear();
+ }
- if (mData->mLooper != NULL) {
- mData->mLooper->unregisterHandler(mData->mHandler->id());
- mData->mLooper->stop();
- mData->mLooper.clear();
+ if (mData->mLooper != NULL) {
+ if (mData->mHandler != NULL) {
+ mData->mLooper->unregisterHandler(mData->mHandler->id());
+ }
+ mData->mLooper->stop();
+ mData->mLooper.clear();
+ }
+ delete mData;
}
- delete mData;
return AMEDIA_OK;
}