不是MediaCodec配置方法的永久性崩溃

时间:2015-05-04 16:21:02

标签: android mediacodec

当我尝试以下一种方式配置MediaCodec时,我抓住了android.media.MediaCodec $ CodecException:错误0x80001001:

MediaFormat outputFormat = new MediaFormat();
outputFormat.setString(MediaFormat.KEY_MIME, COMPRESSED_AUDIO_FILE_MIME_TYPE);
outputFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 2);
outputFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, frequency);
outputFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
outputFormat.setInteger(MediaFormat.KEY_BIT_RATE, COMPRESSED_AUDIO_FILE_BIT_RATE);
outputFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 0);

MediaCodec codec = MediaCodec.createEncoderByType(COMPRESSED_AUDIO_FILE_MIME_TYPE);
codec.configure(outputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
codec.start();

崩溃的完整记录:

E/OMXMaster﹕ A component of name 'OMX.qcom.audio.decoder.aac' already exists, ignoring this one.
E/ACodec﹕ [OMX.google.aac.encoder] configureCodec returning error -38
E/ACodec﹕ signalError(omxError 0x80001001, internalError -2147483648)
E/MediaCodec﹕ Codec reported err 0x80001001, actionCode 0, while in state 3
E/MediaCodec﹕ configure failed with err 0x80001001, resetting...
I/OMXClient﹕ Using client-side OMX mux.
E/OMXMaster﹕ A component of name 'OMX.qcom.audio.decoder.aac' already exists, ignoring this one.

因此,正如我所理解的那样,问题出现在本机代码中。但它只出现在某些设备上 - 例如在带有Android 5.1的Nexus 7上,而具有相同Android版本的Nexus 10可以完美运行。

我似乎找到了MediaCodec的来源和崩溃的地方。这里是链接http://sourceforge.net/p/opencore-amr/vo-aacenc/ci/2418ead75aa9cdaf01cb4286f38fb7be2d48bd8d/tree/aacenc/SoftAACEncoder2.cpp#l362

1 个答案:

答案 0 :(得分:0)

实际上我的音频文件的WAV标题有问题。我在asynctask中运行了转换,但在运行后写了一个标题。所以,有时我试图转换没有标题的wav文件。因为我从wav标题中提取了一些参数(比如频率等),我得到了0值。因此,MediaCodec无法配置和崩溃。