0

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.

Martin L.
  • 3,006
  • 6
  • 36
  • 60
  • You probably know by now but for anyone else in the same situation.. Basically M4A (and MP4) are not designed as realtime streaming formats. Their decoding relies on referencing the metadata, which in turn can only exist when the file is complete (since it tells "What" is "Where" in the bytes). Hence the meta is usually at the end of file. Of-course after recording you can "move" it to the front for online streaming... – VC.One Sep 23 '14 at 20:55
  • 1
    Thanks for the details VC :) I meanwhile decided to not continue with AAC but stay with MP3 instead. – Martin L. Sep 23 '14 at 20:56
  • I liked because MP3 would have been the best solution here for you. If you ever go back to AAC you could keep ADTS only if you DONT use `audio/mp4a-latm` but I dont use Android so I dont know what other options you got. – VC.One Sep 23 '14 at 21:06

0 Answers0