我已经使用MediaCodec成功实现了原始AAC-LC的编码/解码。我使用here描述的相同技术对数据进行编码。但是,我存储原始AAC数据(没有标头),然后在我通过MediaCodec解码器传递数据时动态附加标头。这一切都完全适用于运行Android 4.4的Nexus 4和Nexus 5。但是,在Galaxy Nexus(运行Android 4.3)上,我得到了:
W/SoftAAC2(1234): AAC decoder returned error 16388, substituting silence
错误16388表示decode frame error。
我已尝试使用和不使用初始MediaCodec.BUFFER_FLAG_CODEC_CONFIG,但这并没有什么不同。
这是最简单的情况(使用配置包)来重现错误:
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);
}
显然代码还有很多,但这包括所有已执行的代码,直到错误消息为止。
答案 0 :(得分:2)
解决方案是不包含ADTS标头。 4.3和4.4都支持没有ADTS头的数据包。