2

The following code is for configuring an AAC encoder:

mfAACEncoder = new MediaFormat();
mfAACEncoder.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
mfAACEncoder.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
mfAACEncoder.setInteger(MediaFormat.KEY_SAMPLE_RATE, iClockRateAudio);
mfAACEncoder.setInteger(MediaFormat.KEY_BIT_RATE, 64 * 1024);//AAC-HE 64kbps
mfAACEncoder.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);

//https://stackoverflow.com/questions/21284874/illegal-state-exception-when-calling-mediacodec-configure
mfAACEncoder.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 0);

mcAACEncoder = MediaCodec.createDecoderByType("audio/mp4a-latm");
mcAACEncoder.configure(mfAACEncoder, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);

mcAACEncoder.configure() generates the following in logcat:

06-22 11:13:09.919 4203-4666/net.mydomain.myapp I/MediaCodec: Found 0 pieces of codec specific data.
06-22 11:13:09.919 4203-4666/net.mydomain.myapp D/ACodec: onConfigureComponent
06-22 11:13:09.919 4203-4666/net.mydomain.myapp E/OMXNodeInstance: setParameter(1:google.aac.decoder, ParamStandardComponentRole(0x1000017)) ERROR: Undefined(0x80001001)
06-22 11:13:09.920 4203-4666/net.mydomain.myapp W/ACodec: [OMX.google.aac.decoder] Failed to set standard component role 'audio_encoder.aac'.
06-22 11:13:09.920 4203-4666/net.mydomain.myapp E/ACodec: setComponentRole err 80000000
06-22 11:13:09.920 4203-4666/net.mydomain.myapp E/ACodec: [OMX.google.aac.decoder] configureCodec returning error 80000000
06-22 11:13:09.920 4203-4666/net.mydomain.myapp E/ACodec: signalError(omxError 0x80001001, internalError -2147483648)
06-22 11:13:09.920 4203-4666/net.mydomain.myapp E/MediaCodec: Codec reported err 0x80001001, actionCode 0, while in state 3
06-22 11:13:09.933 4203-4632/net.mydomain.myapp D/ACodec: [OMX.MTK.VIDEO.DECODER.AVC] onOutputBufferDrained ID 0xb4031220
06-22 11:13:09.933 4203-4632/net.mydomain.myapp D/ACodec: queue NativeWindow
06-22 11:13:09.941 4203-4665/net.mydomain.myapp E/MediaCodec: configure failed with err 0x80001001, resetting...

Could anyone offer a tip on how to remedy this?

As indicated in the code, the solution of this thread has already been implemented.

Community
  • 1
  • 1
Hong
  • 17,643
  • 21
  • 81
  • 142

1 Answers1

4

Your issue lies here:

mcAACEncoder = MediaCodec.createDecoderByType("audio/mp4a-latm");
mcAACEncoder.configure(mfAACEncoder, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);

You want to use it as encoder, but you actually create the decoder component instead, but try to use it in the encoder role. To fix it, change the first line to this instead:

mcAACEncoder = MediaCodec.createEncoderByType("audio/mp4a-latm");
mstorsjo
  • 12,983
  • 2
  • 39
  • 62