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

Commit 97ab472f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "stagefright: add HEIF support" into oc-mr1-dev

parents c9f2e060 b51ca280
Loading
Loading
Loading
Loading
+114 −14
Original line number Diff line number Diff line
@@ -30,14 +30,41 @@ namespace android {
class VideoFrame
{
public:
    VideoFrame(): mWidth(0), mHeight(0), mDisplayWidth(0), mDisplayHeight(0), mSize(0),
            mRotationAngle(0), mData(0) {}
    // Construct a VideoFrame object with the specified parameters,
    // will allocate frame buffer if |allocate| is set to true, will
    // allocate buffer to hold ICC data if |iccData| and |iccSize|
    // indicate its presence.
    VideoFrame(uint32_t width, uint32_t height,
            uint32_t displayWidth, uint32_t displayHeight,
            uint32_t angle, uint32_t bpp, bool allocate,
            const void *iccData, size_t iccSize):
        mWidth(width), mHeight(height),
        mDisplayWidth(displayWidth), mDisplayHeight(displayHeight),
        mRotationAngle(angle), mBytesPerPixel(bpp), mRowBytes(bpp * width),
        mSize(0), mIccSize(0), mReserved(0), mData(0), mIccData(0) {
        if (allocate) {
            mSize = mRowBytes * mHeight;
            mData = new uint8_t[mSize];
            if (mData == NULL) {
                mSize = 0;
            }
        }

        if (iccData != NULL && iccSize > 0) {
            mIccSize = iccSize;
            mIccData = new uint8_t[iccSize];
            if (mIccData != NULL) {
                memcpy(mIccData, iccData, iccSize);
            } else {
                mIccSize = 0;
            }
        }
    }

    // Deep copy of both the information fields and the frame data
    VideoFrame(const VideoFrame& copy) {
        mWidth = copy.mWidth;
        mHeight = copy.mHeight;
        mDisplayWidth = copy.mDisplayWidth;
        mDisplayHeight = copy.mDisplayHeight;
        copyInfoOnly(copy);

        mSize = copy.mSize;
        mData = NULL;  // initialize it first
        if (mSize > 0 && copy.mData != NULL) {
@@ -48,26 +75,99 @@ public:
                mSize = 0;
            }
        }
        mRotationAngle = copy.mRotationAngle;

        mIccSize = copy.mIccSize;
        mIccData = NULL;  // initialize it first
        if (mIccSize > 0 && copy.mIccData != NULL) {
            mIccData = new uint8_t[mIccSize];
            if (mIccData != NULL) {
                memcpy(mIccData, copy.mIccData, mIccSize);
            } else {
                mIccSize = 0;
            }
        }
    }

    ~VideoFrame() {
        if (mData != 0) {
            delete[] mData;
        }
        if (mIccData != 0) {
            delete[] mIccData;
        }
    }

    // Copy |copy| to a flattened VideoFrame in IMemory, 'this' must point to
    // a chunk of memory back by IMemory of size at least getFlattenedSize()
    // of |copy|.
    void copyFlattened(const VideoFrame& copy) {
        copyInfoOnly(copy);

        mSize = copy.mSize;
        mData = NULL;  // initialize it first
        if (copy.mSize > 0 && copy.mData != NULL) {
            memcpy(getFlattenedData(), copy.mData, copy.mSize);
        }

        mIccSize = copy.mIccSize;
        mIccData = NULL;  // initialize it first
        if (copy.mIccSize > 0 && copy.mIccData != NULL) {
            memcpy(getFlattenedIccData(), copy.mIccData, copy.mIccSize);
        }
    }

    // Calculate the flattened size to put it in IMemory
    size_t getFlattenedSize() const {
        return sizeof(VideoFrame) + mSize + mIccSize;
    }

    // Get the pointer to the frame data in a flattened VideoFrame in IMemory
    uint8_t* getFlattenedData() const {
        return (uint8_t*)this + sizeof(VideoFrame);
    }

    // Get the pointer to the ICC data in a flattened VideoFrame in IMemory
    uint8_t* getFlattenedIccData() const {
        return (uint8_t*)this + sizeof(VideoFrame) + mSize;
    }

    // Intentional public access modifier:
    uint32_t mWidth;
    uint32_t mHeight;
    uint32_t mDisplayWidth;
    uint32_t mDisplayHeight;
    uint32_t mWidth;           // Decoded image width before rotation
    uint32_t mHeight;          // Decoded image height before rotation
    uint32_t mDisplayWidth;    // Display width before rotation
    uint32_t mDisplayHeight;   // Display height before rotation
    int32_t  mRotationAngle;   // Rotation angle, clockwise, should be multiple of 90
    uint32_t mBytesPerPixel;   // Number of bytes per pixel
    uint32_t mRowBytes;        // Number of bytes per row before rotation
    uint32_t mSize;            // Number of bytes in mData
    int32_t  mRotationAngle;   // rotation angle, clockwise, should be multiple of 90
    // mData should be 64 bit aligned to prevent additional padding
    uint32_t mIccSize;         // Number of bytes in mIccData
    uint32_t mReserved;        // (padding to make mData 64-bit aligned)

    // mData should be 64-bit aligned to prevent additional padding
    uint8_t* mData;            // Actual binary data
    // pad structure so it's the same size on 64 bit and 32 bit
    // pad structure so it's the same size on 64-bit and 32-bit
    char     mPadding[8 - sizeof(mData)];

    // mIccData should be 64-bit aligned to prevent additional padding
    uint8_t* mIccData;            // Actual binary data
    // pad structure so it's the same size on 64-bit and 32-bit
    char     mIccPadding[8 - sizeof(mIccData)];

private:
    //
    // Utility methods used only within VideoFrame struct
    //

    // Copy the information fields only
    void copyInfoOnly(const VideoFrame& copy) {
        mWidth = copy.mWidth;
        mHeight = copy.mHeight;
        mDisplayWidth = copy.mDisplayWidth;
        mDisplayHeight = copy.mDisplayHeight;
        mRotationAngle = copy.mRotationAngle;
        mBytesPerPixel = copy.mBytesPerPixel;
        mRowBytes = copy.mRowBytes;
    }
};

}; // namespace android
+1 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ public:
    status_t setDataSource(
            const sp<IDataSource>& dataSource, const char *mime = NULL);
    sp<IMemory> getFrameAtTime(int64_t timeUs, int option,
            int colorFormat = 0, bool metaOnly = false);
            int colorFormat = HAL_PIXEL_FORMAT_RGB_565, bool metaOnly = false);
    sp<IMemory> extractAlbumArt();
    const char* extractMetadata(int keyCode);

+2 −11
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ sp<IMemory> MetadataRetrieverClient::getFrameAtTime(
        ALOGE("failed to capture a video frame");
        return NULL;
    }
    size_t size = sizeof(VideoFrame) + frame->mSize;
    size_t size = frame->getFlattenedSize();
    sp<MemoryHeapBase> heap = new MemoryHeapBase(size, 0, "MetadataRetrieverClient");
    if (heap == NULL) {
        ALOGE("failed to create MemoryDealer");
@@ -225,16 +225,7 @@ sp<IMemory> MetadataRetrieverClient::getFrameAtTime(
        return NULL;
    }
    VideoFrame *frameCopy = static_cast<VideoFrame *>(mThumbnail->pointer());
    frameCopy->mWidth = frame->mWidth;
    frameCopy->mHeight = frame->mHeight;
    frameCopy->mDisplayWidth = frame->mDisplayWidth;
    frameCopy->mDisplayHeight = frame->mDisplayHeight;
    frameCopy->mSize = frame->mSize;
    frameCopy->mRotationAngle = frame->mRotationAngle;
    ALOGV("rotation: %d", frameCopy->mRotationAngle);
    frameCopy->mData = (uint8_t *)frameCopy + sizeof(VideoFrame);
    memcpy(frameCopy->mData, frame->mData, frame->mSize);
    frameCopy->mData = 0;
    frameCopy->copyFlattened(*frame);
    delete frame;  // Fix memory leakage
    return mThumbnail;
}
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ cc_library_shared {
        "FrameRenderTracker.cpp",
        "HTTPBase.cpp",
        "HevcUtils.cpp",
        "ItemTable.cpp",
        "JPEGSource.cpp",
        "MP3Extractor.cpp",
        "MPEG2TSWriter.cpp",
+42 −0
Original line number Diff line number Diff line
@@ -92,6 +92,48 @@ bool DataSource::getUInt64(off64_t offset, uint64_t *x) {
    return true;
}

bool DataSource::getUInt16Var(off64_t offset, uint16_t *x, size_t size) {
    if (size == 2) {
        return getUInt16(offset, x);
    }
    if (size == 1) {
        uint8_t tmp;
        if (readAt(offset, &tmp, 1) == 1) {
            *x = tmp;
            return true;
        }
    }
    return false;
}

bool DataSource::getUInt32Var(off64_t offset, uint32_t *x, size_t size) {
    if (size == 4) {
        return getUInt32(offset, x);
    }
    if (size == 2) {
        uint16_t tmp;
        if (getUInt16(offset, &tmp)) {
            *x = tmp;
            return true;
        }
    }
    return false;
}

bool DataSource::getUInt64Var(off64_t offset, uint64_t *x, size_t size) {
    if (size == 8) {
        return getUInt64(offset, x);
    }
    if (size == 4) {
        uint32_t tmp;
        if (getUInt32(offset, &tmp)) {
            *x = tmp;
            return true;
        }
    }
    return false;
}

status_t DataSource::getSize(off64_t *size) {
    *size = 0;

Loading