简体   繁体   English

使用MediaCodec解码原始AAC音频数据可在Android 4.4上运行,但不能在4.3上运行

[英]Using MediaCodec to decode raw AAC audio data works on Android 4.4 but not 4.3

I have successfully implemented encoding/decoding raw AAC-LC using MediaCodec. 我已经成功使用MediaCodec实现了对原始AAC-LC的编码/解码。 I'm using the same technique described here to encode the data. 我正在使用此处介绍的相同技术对数据进行编码。 However, I store the raw AAC data (without headers) and then attach headers on the fly as I pass the data through a MediaCodec decoder. 但是,我存储原始AAC数据(不包含标头),然后在通过MediaCodec解码器传递数据时即时附加标头。 This all works absolutely perfectly on the Nexus 4 and Nexus 5 both running Android 4.4. 在运行Android 4.4的Nexus 4和Nexus 5上,这一切都绝对完美。 However, on the Galaxy Nexus (running Android 4.3) I get: 但是,在Galaxy Nexus(运行Android 4.3)上,我得到了:

W/SoftAAC2(1234): AAC decoder returned error 16388, substituting silence

Error 16388 means a decode frame error . 错误16388表示解码帧错误

I've tried with and without an initial MediaCodec.BUFFER_FLAG_CODEC_CONFIG but that doesn't make a difference. 我尝试了是否有初始MediaCodec.BUFFER_FLAG_CODEC_CONFIG,但这没有什么区别。

Here is the simplest case (using config packet) to reproduce the error: 这是最简单的情况(使用配置包)来重现该错误:

MediaFormat format = new MediaFormat();
format.setInteger(MediaFormat.KEY_SAMPLE_RATE, 44100);
format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
format.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
format.setInteger(MediaFormat.KEY_IS_ADTS, 1); 

byte[] bytes = new byte[]{(byte) 0x11, (byte)0x90};
ByteBuffer bb = ByteBuffer.wrap(bytes);
format.setByteBuffer("csd-0", bb);

MediaCodec codec = MediaCodec.createDecoderByType("audio/mp4a-latm");
codec.configure(format, null /* surface */, null /* crypto */, 0 /* flags */);
codec.start();
ByteBuffer[] codecInputBuffers = codec.getInputBuffers();

int inputBufIndex = codec.dequeueInputBuffer(TIMEOUT_US);
if (inputBufIndex >= 0) {
    ByteBuffer dstBuf = codecInputBuffers[inputBufIndex];
    byte[] data = {-1, -7, 80, 0, 1, 63, -4, 18, 8}; // values taken from SO answer linked above (chanCfg = 1, packetLen = 9)
    dstBuf.clear();
    dstBuf.put(data);
    codec.queueInputBuffer(inputBufIndex, 0, data.length, 0, MediaCodec.BUFFER_FLAG_CODEC_CONFIG);
}

Obviously there is a lot more to the code than this, but this includes all the executed code up to the point of the error message. 显然,代码要比这多得多,但这包括直到错误消息为止的所有已执行代码。

The solution is to not include the ADTS headers. 解决方案是包括ADTS标头。 Both 4.3 and 4.4 support packets without ADTS headers. 4.3和4.4均支持不带ADTS标头的数据包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM