Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect supported audio encoders on Android to prevent crash "The given audio encoder 2 is not found"

When an Android device does not support a mandatory audio-encoder, you get: (X=numeric index of the encoder)

E/MediaProfiles(4048): The given audio encoder X is not found A/AudioSource(4048): frameworks/base/media/libstagefright/AudioSource.cpp:58 CHECK(channels == 1 || channels == 2) failed. A/libc(4048): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1) In native code. No Exception to react to. App is just force closed.

Is there any way to query an Android >3.x device if AAC AMR-NB and AMR-WB are actually supported? Documentation ( http://developer.android.com/guide/appendix/media-formats.html ) says that these are core media formats and thus always supported. Some actual and common phones out there (of major brands) don't.

MediaCodec.createByCodecName(String name) and Get supported Codec for Android device only works with API16=Android 4.1 but the devices in question are 4.0.x . It also does not list AMR-NB and AAC.

like image 249
Marcus Wolschon Avatar asked Nov 04 '22 11:11

Marcus Wolschon


1 Answers

On your Android device, the media profiles/capabilities are stored in a config file called media_profiles.xml(on ICS/4.0).

Normally, this file is located in /etc folder on the device.

So what you could do is

  1. Connect your device to pc and pull /etc/media_profiles.xml file using adb pull command
  2. Examine the AudioEncoderCap properties. There will be multiple entries for each capbility that is advertised. for ex:

    AudioEncoderCap name="aac" enabled="true" minBitRate="8192" maxBitRate="96000" minSampleRate="8000" maxSampleRate="16000" minChannels="1" maxChannels="1"

  3. If the 'enabled' flag is set to "true" as above, then that capability should be supported by the device. If it is not supported, the 'enabled' flag will be set to "false".

AFAIK, the media codecs framework introduced on jb (4.1) read this/similar config file to expose the device capabilities to the application layer.

Hope this helps.

Thanks!

like image 188
raviu Avatar answered Nov 12 '22 10:11

raviu