【发布时间】:2014-11-22 21:58:21
【问题描述】:
我已经使用 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);
}
显然代码远不止于此,但这包括到错误消息点为止的所有已执行代码。
【问题讨论】:
标签: android aac android-mediacodec