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

Commit 8166b9c2 authored by Dichen Zhang's avatar Dichen Zhang
Browse files

Expose bitDepth to MediaMetadataRetriever

Bug: b/217378477
Test:
Change-Id: I16dabdf9aaabf341a9cebb1624e464155196a5a8
Merged-In: I16dabdf9aaabf341a9cebb1624e464155196a5a8
(cherry picked from commit f406649e)
parent d4f717c8
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -38,13 +38,13 @@ public:
    VideoFrame(uint32_t width, uint32_t height,
    VideoFrame(uint32_t width, uint32_t height,
            uint32_t displayWidth, uint32_t displayHeight,
            uint32_t displayWidth, uint32_t displayHeight,
            uint32_t tileWidth, uint32_t tileHeight,
            uint32_t tileWidth, uint32_t tileHeight,
            uint32_t angle, uint32_t bpp, bool hasData, size_t iccSize):
            uint32_t angle, uint32_t bpp, uint32_t bitDepth, bool hasData, size_t iccSize):
        mWidth(width), mHeight(height),
        mWidth(width), mHeight(height),
        mDisplayWidth(displayWidth), mDisplayHeight(displayHeight),
        mDisplayWidth(displayWidth), mDisplayHeight(displayHeight),
        mTileWidth(tileWidth), mTileHeight(tileHeight), mDurationUs(0),
        mTileWidth(tileWidth), mTileHeight(tileHeight), mDurationUs(0),
        mRotationAngle(angle), mBytesPerPixel(bpp), mRowBytes(bpp * width),
        mRotationAngle(angle), mBytesPerPixel(bpp), mRowBytes(bpp * width),
        mSize(hasData ? (bpp * width * height) : 0),
        mSize(hasData ? (bpp * width * height) : 0),
        mIccSize(iccSize), mReserved(0) {
        mIccSize(iccSize), mBitDepth(bitDepth) {
    }
    }


    void init(const VideoFrame& copy, const void* iccData, size_t iccSize) {
    void init(const VideoFrame& copy, const void* iccData, size_t iccSize) {
@@ -84,7 +84,9 @@ public:
    uint32_t mRowBytes;        // Number of bytes per row before rotation
    uint32_t mRowBytes;        // Number of bytes per row before rotation
    uint32_t mSize;            // Number of bytes of frame data
    uint32_t mSize;            // Number of bytes of frame data
    uint32_t mIccSize;         // Number of bytes of ICC data
    uint32_t mIccSize;         // Number of bytes of ICC data
    uint32_t mReserved;        // (padding to make mData 64-bit aligned)
    uint32_t mBitDepth;        // number of bits per R / G / B channel

    // Adding new items must be 64-bit aligned.
};
};


}; // namespace android
}; // namespace android
+13 −2
Original line number Original line Diff line number Diff line
@@ -47,6 +47,7 @@ void initFrameInfo(HeifFrameInfo *info, const VideoFrame *videoFrame) {
    info->mRotationAngle = videoFrame->mRotationAngle;
    info->mRotationAngle = videoFrame->mRotationAngle;
    info->mBytesPerPixel = videoFrame->mBytesPerPixel;
    info->mBytesPerPixel = videoFrame->mBytesPerPixel;
    info->mDurationUs = videoFrame->mDurationUs;
    info->mDurationUs = videoFrame->mDurationUs;
    info->mBitDepth = videoFrame->mBitDepth;
    if (videoFrame->mIccSize > 0) {
    if (videoFrame->mIccSize > 0) {
        info->mIccData.assign(
        info->mIccData.assign(
                videoFrame->getFlattenedIccData(),
                videoFrame->getFlattenedIccData(),
@@ -377,13 +378,14 @@ bool HeifDecoderImpl::reinit(HeifFrameInfo* frameInfo) {
        //       issue (e.g. by copying).
        //       issue (e.g. by copying).
        VideoFrame* videoFrame = static_cast<VideoFrame*>(sharedMem->unsecurePointer());
        VideoFrame* videoFrame = static_cast<VideoFrame*>(sharedMem->unsecurePointer());


        ALOGV("Image dimension %dx%d, display %dx%d, angle %d, iccSize %d",
        ALOGV("Image dimension %dx%d, display %dx%d, angle %d, iccSize %d, bitDepth %d",
                videoFrame->mWidth,
                videoFrame->mWidth,
                videoFrame->mHeight,
                videoFrame->mHeight,
                videoFrame->mDisplayWidth,
                videoFrame->mDisplayWidth,
                videoFrame->mDisplayHeight,
                videoFrame->mDisplayHeight,
                videoFrame->mRotationAngle,
                videoFrame->mRotationAngle,
                videoFrame->mIccSize);
                videoFrame->mIccSize,
                videoFrame->mBitDepth);


        initFrameInfo(&mImageInfo, videoFrame);
        initFrameInfo(&mImageInfo, videoFrame);


@@ -729,4 +731,13 @@ size_t HeifDecoderImpl::skipScanlines(size_t count) {
    return (mCurScanline > oldScanline) ? (mCurScanline - oldScanline) : 0;
    return (mCurScanline > oldScanline) ? (mCurScanline - oldScanline) : 0;
}
}


uint32_t HeifDecoderImpl::getColorDepth() {
    HeifFrameInfo* info = &mImageInfo;
    if (info != nullptr) {
        return mImageInfo.mBitDepth;
    }

    return 0;
}

} // namespace android
} // namespace android
+2 −0
Original line number Original line Diff line number Diff line
@@ -54,6 +54,8 @@ public:


    size_t skipScanlines(size_t count) override;
    size_t skipScanlines(size_t count) override;


    uint32_t getColorDepth() override;

private:
private:
    struct DecodeThread;
    struct DecodeThread;


+7 −1
Original line number Original line Diff line number Diff line
@@ -47,6 +47,7 @@ struct HeifFrameInfo {
    int32_t  mRotationAngle;           // Rotation angle, clockwise, should be multiple of 90
    int32_t  mRotationAngle;           // Rotation angle, clockwise, should be multiple of 90
    uint32_t mBytesPerPixel;           // Number of bytes for one pixel
    uint32_t mBytesPerPixel;           // Number of bytes for one pixel
    int64_t  mDurationUs;              // Duration of the frame in us
    int64_t  mDurationUs;              // Duration of the frame in us
    uint32_t mBitDepth;                // Number of bits for each of the R/G/B channels
    std::vector<uint8_t> mIccData;     // ICC data array
    std::vector<uint8_t> mIccData;     // ICC data array
};
};


@@ -162,6 +163,11 @@ struct HeifDecoder {
     */
     */
    virtual size_t skipScanlines(size_t count) = 0;
    virtual size_t skipScanlines(size_t count) = 0;


    /*
     * Returns color depth in bits for each of the R/G/B channels.
     */
    virtual uint32_t getColorDepth() = 0;

private:
private:
    HeifDecoder(const HeifFrameInfo&) = delete;
    HeifDecoder(const HeifFrameInfo&) = delete;
    HeifDecoder& operator=(const HeifFrameInfo&) = delete;
    HeifDecoder& operator=(const HeifFrameInfo&) = delete;
+36 −15
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@
#include <datasource/PlayerServiceDataSourceFactory.h>
#include <datasource/PlayerServiceDataSourceFactory.h>
#include <datasource/PlayerServiceFileSource.h>
#include <datasource/PlayerServiceFileSource.h>
#include <media/IMediaHTTPService.h>
#include <media/IMediaHTTPService.h>
#include <media/stagefright/MediaCodecConstants.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/MediaCodecList.h>
#include <media/stagefright/MediaCodecList.h>
@@ -194,17 +195,6 @@ sp<IMemory> StagefrightMetadataRetriever::getImageInternal(
        return NULL;
        return NULL;
    }
    }


    if (metaOnly) {
        return FrameDecoder::getMetadataOnly(trackMeta, colorFormat, thumbnail);
    }

    sp<IMediaSource> source = mExtractor->getTrack(i);

    if (source.get() == NULL) {
        ALOGE("unable to instantiate image track.");
        return NULL;
    }

    const char *mime;
    const char *mime;
    bool isHeif = false;
    bool isHeif = false;
    if (!trackMeta->findCString(kKeyMIMEType, &mime)) {
    if (!trackMeta->findCString(kKeyMIMEType, &mime)) {
@@ -223,16 +213,47 @@ sp<IMemory> StagefrightMetadataRetriever::getImageInternal(
        trackMeta->setCString(kKeyMIMEType, mime);
        trackMeta->setCString(kKeyMIMEType, mime);
    }
    }


    bool preferhw = property_get_bool(
            "media.stagefright.thumbnail.prefer_hw_codecs", false);
    uint32_t flags = preferhw ? 0 : MediaCodecList::kPreferSoftwareCodecs;
    Vector<AString> matchingCodecs;
    sp<AMessage> format = new AMessage;
    sp<AMessage> format = new AMessage;
    status_t err = convertMetaDataToMessage(trackMeta, &format);
    status_t err = convertMetaDataToMessage(trackMeta, &format);
    if (err != OK) {
    if (err != OK) {
        format = NULL;
        format = NULL;
    }
    }


    uint32_t bitDepth = 8;
    if (!strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_HEVC)) {
        int32_t profile;
        if (format->findInt32("profile", &profile)) {
            if (HEVCProfileMain10 == profile || HEVCProfileMain10HDR10 == profile ||
                    HEVCProfileMain10HDR10Plus == profile) {
                  bitDepth = 10;
            }
        }
    } else if (!strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_AV1)) {
        int32_t profile;
        if (format->findInt32("profile", &profile)) {
            if (AV1ProfileMain10 == profile || AV1ProfileMain10HDR10 == profile ||
                    AV1ProfileMain10HDR10Plus == profile) {
                  bitDepth = 10;
            }
        }
    }

    if (metaOnly) {
        return FrameDecoder::getMetadataOnly(trackMeta, colorFormat, thumbnail, bitDepth);
    }

    sp<IMediaSource> source = mExtractor->getTrack(i);

    if (source.get() == NULL) {
        ALOGE("unable to instantiate image track.");
        return NULL;
    }

    bool preferhw = property_get_bool(
            "media.stagefright.thumbnail.prefer_hw_codecs", false);
    uint32_t flags = preferhw ? 0 : MediaCodecList::kPreferSoftwareCodecs;
    Vector<AString> matchingCodecs;

    // If decoding thumbnail check decoder supports thumbnail dimensions instead
    // If decoding thumbnail check decoder supports thumbnail dimensions instead
    int32_t thumbHeight, thumbWidth;
    int32_t thumbHeight, thumbWidth;
    if (thumbnail && format != NULL
    if (thumbnail && format != NULL
Loading