MediaCodec: don't crash on concurrent release/start/configure
Bug: 30739815
Test: atest CtsMediaTestCases:MediaCodecTest#testAsyncRelease
Change-Id: I6516a43a698bca2d5e8de724d5e7d84d84795449
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp
index 9c58e05..d4e4000 100644
--- a/media/libstagefright/MediaCodec.cpp
+++ b/media/libstagefright/MediaCodec.cpp
@@ -1973,10 +1973,11 @@
case kWhatComponentConfigured:
{
- if (mState == UNINITIALIZED || mState == INITIALIZED) {
- // In case a kWhatError message came in and replied with error,
+ if (mState == RELEASING || mState == UNINITIALIZED || mState == INITIALIZED) {
+ // In case a kWhatError or kWhatRelease message came in and replied,
// we log a warning and ignore.
- ALOGW("configure interrupted by error, current state %d", mState);
+ ALOGW("configure interrupted by error or release, current state %d",
+ mState);
break;
}
CHECK_EQ(mState, CONFIGURING);
@@ -2067,6 +2068,13 @@
case kWhatStartCompleted:
{
+ if (mState == RELEASING || mState == UNINITIALIZED) {
+ // In case a kWhatRelease message came in and replied,
+ // we log a warning and ignore.
+ ALOGW("start interrupted by release, current state %d", mState);
+ break;
+ }
+
CHECK_EQ(mState, STARTING);
if (mIsVideo) {
addResource(
@@ -2632,11 +2640,12 @@
break;
}
- // If we're flushing, or we're stopping but received a release
- // request, post the reply for the pending call first, and consider
- // it done. The reply token will be replaced after this, and we'll
- // no longer be able to reply.
- if (mState == FLUSHING || mState == STOPPING) {
+ // If we're flushing, stopping, configuring or starting but
+ // received a release request, post the reply for the pending call
+ // first, and consider it done. The reply token will be replaced
+ // after this, and we'll no longer be able to reply.
+ if (mState == FLUSHING || mState == STOPPING
+ || mState == CONFIGURING || mState == STARTING) {
(new AMessage)->postReply(mReplyID);
}