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

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

Thumbnail的返回类型是Bitmap。

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

thumbnail的处理流程和读取缩略图thumbnail所在sample的index的方法_第1张图片

寻找缩略图所在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;
}

你可能感兴趣的:(thumbnail的处理流程和读取缩略图thumbnail所在sample的index的方法)