I have successfully implemented encoding/decoding raw AAC-LC using MediaCodec. 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. This all works absolutely perfectly on the Nexus 4 and Nexus 5 both running Android 4.4. However, on the Galaxy Nexus (running Android 4.3) I get:
W/SoftAAC2(1234): AAC decoder returned error 16388, substituting silence Error 16388 means a decode frame error.
I've tried with and without an initial MediaCodec.BUFFER_FLAG_CODEC_CONFIG but that doesn't make a difference.
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.