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

Commit 14e8740f authored by Wonsik Kim's avatar Wonsik Kim
Browse files

stagefright: fix buffer array population for secure input

Bug: 32474779
Test: Play secure content in Play Movies app
Change-Id: I89c99c7d8ed9fe88f756579447ec4bbf886be59f
parent d4370268
Loading
Loading
Loading
Loading
+19 −12
Original line number Diff line number Diff line
@@ -1333,12 +1333,30 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
                        static_cast<CodecBase::PortDescription *>(obj.get());

                    size_t numBuffers = portDesc->countBuffers();

                    size_t totalSize = 0;
                    for (size_t i = 0; i < numBuffers; ++i) {
                        if (portIndex == kPortIndexInput && mCrypto != NULL) {
                            totalSize += portDesc->bufferAt(i)->capacity();
                        }
                    }

                    if (totalSize) {
                        mDealer = new MemoryDealer(totalSize, "MediaCodec");
                    }

                    for (size_t i = 0; i < numBuffers; ++i) {
                        BufferInfo info;
                        info.mBufferID = portDesc->bufferIDAt(i);
                        info.mOwnedByClient = false;
                        sp<MediaCodecBuffer> buffer = portDesc->bufferAt(i);
                        if (portIndex == kPortIndexInput && mCrypto != NULL) {
                            info.mSharedEncryptedBuffer = mDealer->allocate(buffer->capacity());
                            buffer = new SharedMemoryBuffer(
                                    mInputFormat, info.mSharedEncryptedBuffer);
                        }
                        buffers->push_back(info);
                        mPortBufferArrays[portIndex].push_back(portDesc->bufferAt(i));
                        mPortBufferArrays[portIndex].push_back(buffer);
                    }

                    if (portIndex == kPortIndexOutput) {
@@ -2380,17 +2398,6 @@ size_t MediaCodec::updateBuffers(
    sp<MediaCodecBuffer> buffer = static_cast<MediaCodecBuffer *>(obj.get());

    Vector<BufferInfo> *buffers = &mPortBuffers[portIndex];
    if (portIndex == kPortIndexInput && mCrypto != NULL && mDealer == NULL) {
        // Lazy initialization for encrypted buffers.
        size_t capacity = buffer->capacity();
        size_t totalSize = capacity * buffers->size();

        mDealer = new MemoryDealer(totalSize, "MediaCodec");
        for (size_t i = 0; i < buffers->size(); ++i) {
            BufferInfo *info = &buffers->editItemAt(i);
            info->mSharedEncryptedBuffer = mDealer->allocate(capacity);
        }
    }

    for (size_t i = 0; i < buffers->size(); ++i) {
        BufferInfo *info = &buffers->editItemAt(i);