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

Commit 7954ccd5 authored by Wonsik Kim's avatar Wonsik Kim
Browse files

MediaCodec: use setInternalStateLocked to set Linear/GraphicBlock contexts

Bug: 148410627
Test: atest CtsMediaTestCases:MediaCodecBlockModelTest
Change-Id: I8d18c30b2036d0da41d0fad943498aa2ad139c45
parent 12ce8338
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -724,18 +724,21 @@ status_t JMediaCodec::getOutputFrame(
    }

    if (buffer->size() > 0) {
        // asC2Buffer clears internal reference, so set the reference again.
        std::shared_ptr<C2Buffer> c2Buffer = buffer->asC2Buffer();
        buffer->copy(c2Buffer);
        if (c2Buffer) {
            // asC2Buffer clears internal reference, so set the reference again.
            buffer->copy(c2Buffer);
            switch (c2Buffer->data().type()) {
                case C2BufferData::LINEAR: {
                    std::unique_ptr<JMediaCodecLinearBlock> context{new JMediaCodecLinearBlock};
                    context->mBuffer = c2Buffer;
                    ScopedLocalRef<jobject> linearBlock{env, env->NewObject(
                            gLinearBlockInfo.clazz, gLinearBlockInfo.ctorId)};
                    env->SetLongField(
                            linearBlock.get(), gLinearBlockInfo.contextId, (jlong)context.release());
                    env->CallVoidMethod(
                            linearBlock.get(),
                            gLinearBlockInfo.setInternalStateId,
                            (jlong)context.release(),
                            true);
                    env->SetObjectField(frame, gFields.outputFrameLinearBlockID, linearBlock.get());
                    break;
                }
@@ -744,8 +747,11 @@ status_t JMediaCodec::getOutputFrame(
                    context->mBuffer = c2Buffer;
                    ScopedLocalRef<jobject> graphicBlock{env, env->NewObject(
                            gGraphicBlockInfo.clazz, gGraphicBlockInfo.ctorId)};
                    env->SetLongField(
                            graphicBlock.get(), gGraphicBlockInfo.contextId, (jlong)context.release());
                    env->CallVoidMethod(
                            graphicBlock.get(),
                            gGraphicBlockInfo.setInternalStateId,
                            (jlong)context.release(),
                            true);
                    env->SetObjectField(frame, gFields.outputFrameGraphicBlockID, graphicBlock.get());
                    break;
                }
@@ -761,16 +767,22 @@ status_t JMediaCodec::getOutputFrame(
                context->mLegacyBuffer = buffer;
                ScopedLocalRef<jobject> linearBlock{env, env->NewObject(
                        gLinearBlockInfo.clazz, gLinearBlockInfo.ctorId)};
                env->SetLongField(
                        linearBlock.get(), gLinearBlockInfo.contextId, (jlong)context.release());
                env->CallVoidMethod(
                        linearBlock.get(),
                        gLinearBlockInfo.setInternalStateId,
                        (jlong)context.release(),
                        true);
                env->SetObjectField(frame, gFields.outputFrameLinearBlockID, linearBlock.get());
            } else {
                std::unique_ptr<JMediaCodecGraphicBlock> context{new JMediaCodecGraphicBlock};
                context->mLegacyBuffer = buffer;
                ScopedLocalRef<jobject> graphicBlock{env, env->NewObject(
                        gGraphicBlockInfo.clazz, gGraphicBlockInfo.ctorId)};
                env->SetLongField(
                        graphicBlock.get(), gGraphicBlockInfo.contextId, (jlong)context.release());
                env->CallVoidMethod(
                        graphicBlock.get(),
                        gGraphicBlockInfo.setInternalStateId,
                        (jlong)context.release(),
                        true);
                env->SetObjectField(frame, gFields.outputFrameGraphicBlockID, graphicBlock.get());
            }
        }