Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know Android decoder MediaCodec.createDecoderByType(type) is Hardware or software decoder?

Is there a way to find out if the decoder that received using MediaCodec.createDecoderByType(type) is a hardware decoder or a software decoder?

like image 737
Saeid Farivar Avatar asked Dec 25 '22 05:12

Saeid Farivar


2 Answers

There is no real formal flag for indicating whether a codec is a hardware or software codec. In practice, you can do this, though:

MediaCodec codec = MediaCodec.createDecoderByType(type);
if (codec.getName().startsWith("OMX.google.")) {
    // Is a software codec
}

(The MediaCodec.getName() method is available since API level 18. For lower API levels, you instead need to iterate over the entries in MediaCodecList and manually pick the right codec that fits your needs instead.)

like image 115
mstorsjo Avatar answered Apr 26 '23 23:04

mstorsjo


Putting it here for anyone it might help. According to code for libstagefright, any codec which starts with OMX.google. or c2.android. or does not start with (OMX. and c2.) are all software codecs.

//static
bool MediaCodecList::isSoftwareCodec(const AString &componentName) {
    return componentName.startsWithIgnoreCase("OMX.google.")
            || componentName.startsWithIgnoreCase("c2.android.")
            || (!componentName.startsWithIgnoreCase("OMX.")
                    && !componentName.startsWithIgnoreCase("c2."));
}

Source:
https://android.googlesource.com/platform/frameworks/av/+/master/media/libstagefright/MediaCodecList.cpp#320

like image 38
lightBullet Avatar answered Apr 26 '23 23:04

lightBullet