thumbnail的处理流程和读取缩略图thumbnail所在sample的index的方法

取得video thumbnail的处理流程如下图所示,取得image的thumbnail的处理流程类似,只是取得image thumbnail的函数变成了ThumbnailUtils.createImageThumbnail。

Thumbnail的返回类型是Bitmap。

MediaProvider的update函数会调用requestMediaThumbnail获取缩略图,然后再调用MediaThumbRequest类的execute()函数,在execute()函数调用了ThumbnailUtils.createVideoThumbnail去获取缩略图。

寻找缩略图所在sample的index的方法在SampleTable::findThumbnailSample函数中,在要寻找的前numSamplesToScan个samples 中,寻找size最大的sample作为缩略图的sample index。

status_t SampleTable::findThumbnailSample(uint32_t *sample_index) {
    Mutex::Autolock autoLock(mLock);

    if (mSyncSampleOffset < 0) {
        // All samples are sync-samples.
        *sample_index = 0;
        return OK;
    }

    uint32_t bestSampleIndex = 0;
    size_t maxSampleSize = 0;

    static const size_t kMaxNumSyncSamplesToScan = 20; // 最大查找20个samples

    // Consider the first kMaxNumSyncSamplesToScan sync samples and
    // pick the one with the largest (compressed) size as the thumbnail.

    size_t numSamplesToScan = mNumSyncSamples;
    if (numSamplesToScan > kMaxNumSyncSamplesToScan) {
        numSamplesToScan = kMaxNumSyncSamplesToScan;
    }

    for (size_t i = 0; i < numSamplesToScan; ++i) {
        uint32_t x = mSyncSamples[i];

        // Now x is a sample index.
        size_t sampleSize;
        status_t err = getSampleSize_l(x, &sampleSize);
        if (err != OK) {
            return err;
        }

        if (i == 0 || sampleSize > maxSampleSize) { // 寻找size最大的一个sample当做thumbnail的sample
            bestSampleIndex = x;
            maxSampleSize = sampleSize;
        }
    }

    *sample_index = bestSampleIndex;

    return OK;
}

发布了270 篇原创文章 · 获赞 274 · 访问量 377万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览