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

Commit 28edbba6 authored by Lajos Molnar's avatar Lajos Molnar
Browse files

stagefright: account for alignment in MemoryDealer

Bug: 27722308
Change-Id: I4e4f08db36e8311d71374e7de096480047bbb6cf
parent a8d309df
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -55,6 +55,10 @@ struct CodecBase : public AHandler, /* static */ ColorUtils {
        kWhatOutputFramesRendered = 'outR',
    };

    enum {
        kMaxCodecBufferSize = 8192 * 4096 * 4, // 8K RGBA
    };

    virtual void setNotificationMessage(const sp<AMessage> &msg) = 0;

    virtual void initiateAllocateComponent(const sp<AMessage> &msg) = 0;
+13 −3
Original line number Diff line number Diff line
@@ -799,16 +799,26 @@ status_t ACodec::allocateBuffersOnPort(OMX_U32 portIndex) {
                bufSize = max(bufSize, (int32_t)sizeof(VideoNativeMetadata));
            }

            size_t alignment = MemoryDealer::getAllocationAlignment();

            ALOGV("[%s] Allocating %u buffers of size %d/%d (from %u using %s) on %s port",
                    mComponentName.c_str(),
                    def.nBufferCountActual, bufSize, allottedSize, def.nBufferSize, asString(type),
                    portIndex == kPortIndexInput ? "input" : "output");

            if (bufSize == 0 || def.nBufferCountActual > SIZE_MAX / bufSize) {
            if (bufSize == 0 || bufSize > kMaxCodecBufferSize) {
                ALOGE("b/22885421");
                return NO_MEMORY;
            }

            // don't modify bufSize as OMX may not expect it to increase after negotiation
            size_t alignedSize = align(bufSize, alignment);
            if (def.nBufferCountActual > SIZE_MAX / alignedSize) {
                ALOGE("b/22885421");
                return NO_MEMORY;
            }
            size_t totalSize = def.nBufferCountActual * bufSize;

            size_t totalSize = def.nBufferCountActual * alignedSize;
            mDealer[portIndex] = new MemoryDealer(totalSize, "ACodec");

            for (OMX_U32 i = 0; i < def.nBufferCountActual && err == OK; ++i) {
@@ -1116,7 +1126,7 @@ status_t ACodec::allocateOutputMetadataBuffers() {

    size_t bufSize = mOutputMetadataType == kMetadataBufferTypeANWBuffer ?
            sizeof(struct VideoNativeMetadata) : sizeof(struct VideoGrallocMetadata);
    size_t totalSize = bufferCount * bufSize;
    size_t totalSize = bufferCount * align(bufSize, MemoryDealer::getAllocationAlignment());
    mDealer[kPortIndexOutput] = new MemoryDealer(totalSize, "ACodec");

    // Dequeue buffers and send them to OMX