Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 07a9995b authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "MediaCodec: more buffer state cleanup" into main am: edab2cea am: 8e8a3d5b

parents 2fb6ef44 8e8a3d5b
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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"
+33 −8
Original line number Diff line number Diff line
@@ -2018,6 +2018,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);
@@ -4497,9 +4498,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;
                    }
@@ -4578,9 +4586,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;
                    }
@@ -6025,7 +6040,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;
@@ -6071,6 +6085,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;
@@ -6129,6 +6147,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();
            }
@@ -6481,6 +6501,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();

@@ -6497,6 +6518,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);
}

@@ -6565,6 +6587,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();
@@ -6677,6 +6700,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;