Loading media/aconfig/codec_fwk.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,16 @@ flag { bug: "201479783" } flag { name: "codec_buffer_state_cleanup" namespace: "codec_fwk" description: "Bugfix flag for more buffer state cleanup in MediaCodec" bug: "343502509" metadata { purpose: PURPOSE_BUGFIX } } flag { name: "dataspace_v0_partial" namespace: "codec_fwk" Loading media/libstagefright/MediaCodec.cpp +33 −8 Original line number Diff line number Diff line Loading @@ -2015,6 +2015,7 @@ bool MediaCodec::discardDecodeOnlyOutputBuffer(size_t index) { int32_t flags; CHECK(buffer->meta()->findInt32("flags", &flags)); if (flags & BUFFER_FLAG_DECODE_ONLY) { ALOGV("discardDecodeOnlyOutputBuffer: mPortBuffers[out][%zu] NOT owned by client", index); info->mOwnedByClient = false; info->mData.clear(); mBufferChannel->discardBuffer(buffer); Loading Loading @@ -4494,9 +4495,16 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { { /* size_t index = */updateBuffers(kPortIndexInput, msg); if (mState == FLUSHING || mState == STOPPING || mState == RELEASING) { bool inStateToReturnBuffers = mState == FLUSHING || mState == STOPPING || mState == RELEASING; if (android::media::codec::provider_->codec_buffer_state_cleanup()) { // Late callbacks from the codec could arrive here // after the codec is already stopped or released. inStateToReturnBuffers = mState == FLUSHING || mState == STOPPING || mState == INITIALIZED || mState == RELEASING || mState == UNINITIALIZED; } if (inStateToReturnBuffers) { returnBuffersToCodecOnPort(kPortIndexInput); break; } Loading Loading @@ -4575,9 +4583,16 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { /* size_t index = */updateBuffers(kPortIndexOutput, msg); if (mState == FLUSHING || mState == STOPPING || mState == RELEASING) { bool inStateToReturnBuffers = mState == FLUSHING || mState == STOPPING || mState == RELEASING; if (android::media::codec::provider_->codec_buffer_state_cleanup()) { // Late callbacks from the codec could arrive here // after the codec is already stopped or released. inStateToReturnBuffers = mState == FLUSHING || mState == STOPPING || mState == INITIALIZED || mState == RELEASING || mState == UNINITIALIZED; } if (inStateToReturnBuffers) { returnBuffersToCodecOnPort(kPortIndexOutput); break; } Loading Loading @@ -6022,7 +6037,6 @@ status_t MediaCodec::queueCSDInputBuffer(size_t bufferIndex) { return -EINVAL; } if (codecInputData->data() == NULL) { ALOGV("Input buffer %zu is not properly allocated", bufferIndex); mErrorLog.log(LOG_TAG, base::StringPrintf( "Fatal error: input buffer %zu is not properly allocated", bufferIndex)); return -EINVAL; Loading Loading @@ -6068,6 +6082,10 @@ void MediaCodec::setState(State newState) { mInputFormat.clear(); mOutputFormat.clear(); if (android::media::codec::provider_->codec_buffer_state_cleanup()) { mCSD.clear(); mLeftover.clear(); } mFlags &= ~kFlagOutputFormatChanged; mFlags &= ~kFlagOutputBuffersChanged; mFlags &= ~kFlagStickyError; Loading Loading @@ -6126,6 +6144,8 @@ void MediaCodec::returnBuffersToCodecOnPort(int32_t portIndex, bool isReclaim) { ALOGD("port %d buffer %zu still owned by client when codec is reclaimed", portIndex, i); } else { ALOGV("returnBuffersToCodecOnPort: mPortBuffers[%s][%zu] NOT owned by client", portIndex == kPortIndexInput ? "in" : "out", i); info->mOwnedByClient = false; info->mData.clear(); } Loading Loading @@ -6478,6 +6498,7 @@ status_t MediaCodec::onQueueInputBuffer(const sp<AMessage> &msg) { // synchronization boundary for getBufferAndFormat Mutex::Autolock al(mBufferLock); ALOGV("onQueueInputBuffer: mPortBuffers[in][%zu] NOT owned by client", index); info->mOwnedByClient = false; info->mData.clear(); Loading @@ -6494,6 +6515,7 @@ status_t MediaCodec::handleLeftover(size_t index) { sp<AMessage> msg = mLeftover.front(); mLeftover.pop_front(); msg->setSize("index", index); ALOGV("handleLeftover(%zu)", index); return onQueueInputBuffer(msg); } Loading Loading @@ -6562,6 +6584,7 @@ status_t MediaCodec::onReleaseOutputBuffer(const sp<AMessage> &msg) { sp<MediaCodecBuffer> buffer; { Mutex::Autolock al(mBufferLock); ALOGV("onReleaseOutputBuffer: mPortBuffers[out][%zu] NOT owned by client", index); info->mOwnedByClient = false; buffer = info->mData; info->mData.clear(); Loading Loading @@ -6674,6 +6697,8 @@ ssize_t MediaCodec::dequeuePortBuffer(int32_t portIndex) { { Mutex::Autolock al(mBufferLock); ALOGV("dequeuePortBuffer: mPortBuffers[%s][%zu] checking if not owned by client", portIndex == kPortIndexInput ? "in" : "out", index); CHECK(!info->mOwnedByClient); info->mOwnedByClient = true; Loading Loading
media/aconfig/codec_fwk.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,16 @@ flag { bug: "201479783" } flag { name: "codec_buffer_state_cleanup" namespace: "codec_fwk" description: "Bugfix flag for more buffer state cleanup in MediaCodec" bug: "343502509" metadata { purpose: PURPOSE_BUGFIX } } flag { name: "dataspace_v0_partial" namespace: "codec_fwk" Loading
media/libstagefright/MediaCodec.cpp +33 −8 Original line number Diff line number Diff line Loading @@ -2015,6 +2015,7 @@ bool MediaCodec::discardDecodeOnlyOutputBuffer(size_t index) { int32_t flags; CHECK(buffer->meta()->findInt32("flags", &flags)); if (flags & BUFFER_FLAG_DECODE_ONLY) { ALOGV("discardDecodeOnlyOutputBuffer: mPortBuffers[out][%zu] NOT owned by client", index); info->mOwnedByClient = false; info->mData.clear(); mBufferChannel->discardBuffer(buffer); Loading Loading @@ -4494,9 +4495,16 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { { /* size_t index = */updateBuffers(kPortIndexInput, msg); if (mState == FLUSHING || mState == STOPPING || mState == RELEASING) { bool inStateToReturnBuffers = mState == FLUSHING || mState == STOPPING || mState == RELEASING; if (android::media::codec::provider_->codec_buffer_state_cleanup()) { // Late callbacks from the codec could arrive here // after the codec is already stopped or released. inStateToReturnBuffers = mState == FLUSHING || mState == STOPPING || mState == INITIALIZED || mState == RELEASING || mState == UNINITIALIZED; } if (inStateToReturnBuffers) { returnBuffersToCodecOnPort(kPortIndexInput); break; } Loading Loading @@ -4575,9 +4583,16 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { /* size_t index = */updateBuffers(kPortIndexOutput, msg); if (mState == FLUSHING || mState == STOPPING || mState == RELEASING) { bool inStateToReturnBuffers = mState == FLUSHING || mState == STOPPING || mState == RELEASING; if (android::media::codec::provider_->codec_buffer_state_cleanup()) { // Late callbacks from the codec could arrive here // after the codec is already stopped or released. inStateToReturnBuffers = mState == FLUSHING || mState == STOPPING || mState == INITIALIZED || mState == RELEASING || mState == UNINITIALIZED; } if (inStateToReturnBuffers) { returnBuffersToCodecOnPort(kPortIndexOutput); break; } Loading Loading @@ -6022,7 +6037,6 @@ status_t MediaCodec::queueCSDInputBuffer(size_t bufferIndex) { return -EINVAL; } if (codecInputData->data() == NULL) { ALOGV("Input buffer %zu is not properly allocated", bufferIndex); mErrorLog.log(LOG_TAG, base::StringPrintf( "Fatal error: input buffer %zu is not properly allocated", bufferIndex)); return -EINVAL; Loading Loading @@ -6068,6 +6082,10 @@ void MediaCodec::setState(State newState) { mInputFormat.clear(); mOutputFormat.clear(); if (android::media::codec::provider_->codec_buffer_state_cleanup()) { mCSD.clear(); mLeftover.clear(); } mFlags &= ~kFlagOutputFormatChanged; mFlags &= ~kFlagOutputBuffersChanged; mFlags &= ~kFlagStickyError; Loading Loading @@ -6126,6 +6144,8 @@ void MediaCodec::returnBuffersToCodecOnPort(int32_t portIndex, bool isReclaim) { ALOGD("port %d buffer %zu still owned by client when codec is reclaimed", portIndex, i); } else { ALOGV("returnBuffersToCodecOnPort: mPortBuffers[%s][%zu] NOT owned by client", portIndex == kPortIndexInput ? "in" : "out", i); info->mOwnedByClient = false; info->mData.clear(); } Loading Loading @@ -6478,6 +6498,7 @@ status_t MediaCodec::onQueueInputBuffer(const sp<AMessage> &msg) { // synchronization boundary for getBufferAndFormat Mutex::Autolock al(mBufferLock); ALOGV("onQueueInputBuffer: mPortBuffers[in][%zu] NOT owned by client", index); info->mOwnedByClient = false; info->mData.clear(); Loading @@ -6494,6 +6515,7 @@ status_t MediaCodec::handleLeftover(size_t index) { sp<AMessage> msg = mLeftover.front(); mLeftover.pop_front(); msg->setSize("index", index); ALOGV("handleLeftover(%zu)", index); return onQueueInputBuffer(msg); } Loading Loading @@ -6562,6 +6584,7 @@ status_t MediaCodec::onReleaseOutputBuffer(const sp<AMessage> &msg) { sp<MediaCodecBuffer> buffer; { Mutex::Autolock al(mBufferLock); ALOGV("onReleaseOutputBuffer: mPortBuffers[out][%zu] NOT owned by client", index); info->mOwnedByClient = false; buffer = info->mData; info->mData.clear(); Loading Loading @@ -6674,6 +6697,8 @@ ssize_t MediaCodec::dequeuePortBuffer(int32_t portIndex) { { Mutex::Autolock al(mBufferLock); ALOGV("dequeuePortBuffer: mPortBuffers[%s][%zu] checking if not owned by client", portIndex == kPortIndexInput ? "in" : "out", index); CHECK(!info->mOwnedByClient); info->mOwnedByClient = true; Loading