Search code examples
androidandroid-mediaplayerandroid-mediacodechardware-acceleration

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?


Solution

  • 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.)