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

Commit fbc97c52 authored by Chong Zhang's avatar Chong Zhang
Browse files

heif: add muxer support for adding still images

This change adds basic support for adding still images to a
heif container.

bug: 63633199

test:
Locally built test app that adds more than one still images
and video sequences to a heif container. Verified the muxed
file can be played by locally built heif viewer app that
uses MediaExtractor/MediaMetadataRetriever/MediaPlayer apis.

Tested media post-submit CTS on Pixel2XL.

Change-Id: I185bbbbed3dbb4e76d64bcf7323ee44a42cc8623
parent ef9fc779
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1425,7 +1425,7 @@ sp<MetaData> ItemTable::getImageMeta(const uint32_t imageIndex) {
    meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_IMAGE_ANDROID_HEIC);

    if (image->itemId == mPrimaryItemId) {
        meta->setInt32(kKeyIsPrimaryImage, 1);
        meta->setInt32(kKeyTrackIsDefault, 1);
    }

    ALOGV("image[%u]: size %dx%d", imageIndex, image->width, image->height);
+36 −35
Original line number Diff line number Diff line
@@ -347,7 +347,7 @@ MPEG4Extractor::MPEG4Extractor(const sp<DataSource> &source, const char *mime)
      mHeaderTimescale(0),
      mIsQT(false),
      mIsHeif(false),
      mIsHeifSequence(false),
      mHasMoovBox(false),
      mPreferHeif(mime != NULL && !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_HEIF)),
      mFirstTrack(NULL),
      mLastTrack(NULL),
@@ -563,9 +563,9 @@ status_t MPEG4Extractor::readMetaData() {
    status_t err;
    bool sawMoovOrSidx = false;

    while (!((!mIsHeif && sawMoovOrSidx && (mMdatFound || mMoofFound)) ||
             (mIsHeif && (mPreferHeif || !mIsHeifSequence)
                     && (mItemTable != NULL) && mItemTable->isValid()))) {
    while (!((mHasMoovBox && sawMoovOrSidx && (mMdatFound || mMoofFound)) ||
             (mIsHeif && (mPreferHeif || !mHasMoovBox) &&
                     (mItemTable != NULL) && mItemTable->isValid()))) {
        off64_t orig_offset = offset;
        err = parseChunk(&offset, 0);

@@ -582,12 +582,9 @@ status_t MPEG4Extractor::readMetaData() {
        }
    }

    if (mIsHeif) {
        uint32_t imageCount = mItemTable->countImages();
        if (imageCount == 0) {
            ALOGE("found no image in heif!");
        } else {
            for (uint32_t imageIndex = 0; imageIndex < imageCount; imageIndex++) {
    if (mIsHeif && (mItemTable != NULL) && (mItemTable->countImages() > 0)) {
        for (uint32_t imageIndex = 0;
                imageIndex < mItemTable->countImages(); imageIndex++) {
            sp<MetaData> meta = mItemTable->getImageMeta(imageIndex);
            if (meta == NULL) {
                ALOGE("heif image %u has no meta!", imageIndex);
@@ -611,7 +608,6 @@ status_t MPEG4Extractor::readMetaData() {
            track->timescale = 0;
        }
    }
    }

    if (mInitCheck == OK) {
        if (findTrackByMimePrefix("video/") != NULL) {
@@ -2512,13 +2508,18 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
            } else {
                if (brandSet.count(FOURCC('m', 'i', 'f', '1')) > 0
                 && brandSet.count(FOURCC('h', 'e', 'i', 'c')) > 0) {
                    mIsHeif = true;
                    ALOGV("identified HEIF image");

                    mIsHeif = true;
                    brandSet.erase(FOURCC('m', 'i', 'f', '1'));
                    brandSet.erase(FOURCC('h', 'e', 'i', 'c'));
                }
                if (brandSet.count(FOURCC('m', 's', 'f', '1')) > 0
                 && brandSet.count(FOURCC('h', 'e', 'v', 'c')) > 0) {
                    mIsHeifSequence = true;
                    ALOGV("identified HEIF image sequence");

                if (!brandSet.empty()) {
                    // This means that the file should have moov box.
                    // It could be any iso files (mp4, heifs, etc.)
                    mHasMoovBox = true;
                    ALOGV("identified HEIF image with other tracks");
                }
            }

+1 −1
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ private:
    uint32_t mHeaderTimescale;
    bool mIsQT;
    bool mIsHeif;
    bool mIsHeifSequence;
    bool mHasMoovBox;
    bool mPreferHeif;

    Track *mFirstTrack, *mLastTrack;
+3 −0
Original line number Diff line number Diff line
@@ -77,6 +77,9 @@ enum output_format {
    /* VP8/VORBIS data in a WEBM container */
    OUTPUT_FORMAT_WEBM = 9,

    /* HEIC data in a HEIF container */
    OUTPUT_FORMAT_HEIF = 10,

    OUTPUT_FORMAT_LIST_END // must be last - used to validate format type
};

+633 −122

File changed.

Preview size limit exceeded, changes collapsed.

Loading