Why can neither Windows Media Player, nor PowerDVD nor any Android-app stream my AAC-stream, but play it once (manually) downloaded?!
I'm continuous recoding (microphone) & compressing PCM-audio inside Android to AAC:
encoder = MediaCodec.createEncoderByType("audio/mp4a-latm");
MediaFormat format = new MediaFormat();
format.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 2);
format.setInteger(MediaFormat.KEY_SAMPLE_RATE, 44100);
format.setInteger(MediaFormat.KEY_BIT_RATE, 64 * 1024);
format.setInteger(MediaFormat.KEY_AAC_PROFILE,
MediaCodecInfo.CodecProfileLevel.AACObjectLC);
encoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
As this produces a raw, headless AAC, I'm also adding the required MPEG-headers for each frame:
private void addADTStoPacket(byte[] packet, int packetLen) {
int profile = 2; // M4A LC
// 39=MediaCodecInfo.CodecProfileLevel.AACObjectELD;
int freqIdx = 4; // 44.1KHz
int chanCfg = 2; // CPE
// fill in ADTS data
packet[0] = (byte) 0xFF;
packet[1] = (byte) 0xF9;
packet[2] = (byte) (((profile - 1) << 6) + (freqIdx << 2) + (chanCfg >> 2));
packet[3] = (byte) (((chanCfg & 3) << 6) + (packetLen >> 11));
packet[4] = (byte) ((packetLen & 0x7FF) >> 3);
packet[5] = (byte) (((packetLen & 7) << 5) + 0x1F);
packet[6] = (byte) 0xFC;
}
And I'm publishing it via an HTTP-socket and the following Content-Type (tested each): audio/mp4a-latm, audio/aac, audio/mp4
No connected player will start with playback, but if I download the file and give it to the same player, it's working without problems.
The socket-part is working very well as it's already used for eg. WAV and MP3-streams, but I cannot get it running for AAC.
Anyone an idea? It's so curious too me.