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

2

4

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

Flywheel answered 9/6, 2016 at 1:32 Comment(3)
@fadden could you help me figure this out.Flywheel
@mstorsjo could you help me figure this out.Flywheel
FWIW, you can't @-summon people to a discussion. People only get pinged if they were already taking part in the discussion.Myopic
S
11

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

Somehow answered 9/6, 2016 at 10:23 Comment(5)
Thanks. I tried it on a Galaxy S6 and the return value when type='video/avc' was 'OMX.Exynos.avc.dec', so I guess it's a hardware decoder?!Flywheel
Yes, that's a hardware decoder - Exynos is the name of the SoC that some Samsung devices use.Somehow
Also, in practice, if a hardware decoder exists, it will most probably be returned by createDecoderByType instead of a software decoder. That is, if you get a software decoder, that's probably because there is no hardware decoder for the format you requested.Somehow
The problem I am having is that even though the decoder is HW accelerated, the CPU usage is almost 100% on some devices (e.g. Sony Android TV). but I see EXO-player is performing so much better in every case.Flywheel
mstorsjo, could you take a look at a media decoder related questionFlywheel
L
4

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

Limy answered 5/12, 2021 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.