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

Commit 45edc1f7 authored by Hangyu Kuang's avatar Hangyu Kuang
Browse files

media: Optimize the thumbnail extraction by sending just one frame.

For thumbnail extraction, MedatadaRetriever only needs to send one frame. This
could lower the CPU usage in extreme usage case.

Bug: 29646892
Change-Id: I86454a58a266a2d8a256a812cd075e401ae778e9
parent b889242a
Loading
Loading
Loading
Loading
+15 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@
#include <utils/Log.h>
#include <utils/Log.h>
#include <gui/Surface.h>
#include <gui/Surface.h>


#include "include/avc_utils.h"
#include "include/StagefrightMetadataRetriever.h"
#include "include/StagefrightMetadataRetriever.h"


#include <media/ICrypto.h>
#include <media/ICrypto.h>
@@ -237,6 +238,15 @@ static VideoFrame *extractVideoFrame(
    int64_t timeUs;
    int64_t timeUs;
    size_t retriesLeft = kRetryCount;
    size_t retriesLeft = kRetryCount;
    bool done = false;
    bool done = false;
    const char *mime;
    bool success = format->findCString(kKeyMIMEType, &mime);
    if (!success) {
        ALOGE("Could not find mime type");
        return NULL;
    }

    bool isAvcOrHevc = !strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_AVC)
            || !strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_HEVC);


    do {
    do {
        size_t inputIndex = -1;
        size_t inputIndex = -1;
@@ -276,6 +286,11 @@ static VideoFrame *extractVideoFrame(
                memcpy(codecBuffer->data(),
                memcpy(codecBuffer->data(),
                        (const uint8_t*)mediaBuffer->data() + mediaBuffer->range_offset(),
                        (const uint8_t*)mediaBuffer->data() + mediaBuffer->range_offset(),
                        mediaBuffer->range_length());
                        mediaBuffer->range_length());
                if (isAvcOrHevc && IsIDR(codecBuffer)) {
                    // Only need to decode one IDR frame.
                    haveMoreInputs = false;
                    flags |= MediaCodec::BUFFER_FLAG_EOS;
                }
            }
            }


            mediaBuffer->release();
            mediaBuffer->release();