                     if (frame_start) {
                         frames.push(new AudioFrame(frame_start, frame_length, frame_length, samplerate));
                     }
-                    if (short == SYNCWORD_3) {
-                        // ADTS header is 9 bytes.
-                        frame_length = ((adts.readUnsignedInt() & 0x0003FFE0) >> 5) - 9;
-                        frame_start = adts.position + 3;
-                        adts.position += frame_length + 3;
-                    } else {
-                        // ADTS header is 7 bytes.
-                        frame_length = ((adts.readUnsignedInt() & 0x0003FFE0) >> 5) - 7;
-                        frame_start = adts.position + 1;
-                        adts.position += frame_length + 1;
-                    }
+                    // protection_absent=1, crc_len = 0,protection_absent=0,crc_len=2
+                    var crc_len : int = (1 - (short & 0x1)) << 1;
+                    // ADTS header is 7+crc_len bytes.
+                    frame_length = ((adts.readUnsignedInt() & 0x0003FFE0) >> 5) - 7 - crc_len;
+                    frame_start = adts.position + 1 + crc_len;
+                    adts.position += frame_length + 1 + crc_len;
                 } else {
                     CONFIG::LOGGING {
-                        Log.debug("no ADTS header found, probing...");
+                        Log.debug2("no ADTS header found, probing...");
                     }
                     adts.position--;
                 }

            // we need at least 6 bytes, 2 for sync word, 4 for frame length
            while ((adts.bytesAvailable > 5) && (short != SYNCWORD) && (short != SYNCWORD_2) && (short != SYNCWORD_3)) {
                short = adts.readUnsignedShort();
            }

            if (short == SYNCWORD || short == SYNCWORD_2 || short == SYNCWORD_3) {
                var profile : uint = (adts.readByte() & 0xF0) >> 6;
                // Correcting zero-index of ADIF and Flash playing only LC/HE.

    CONFIG::LOGGING {
        import org.mangui.hls.utils.Log;
    }
    /** Constants and utilities for the AAC audio format, refer to 
     *  http://wiki.multimedia.cx/index.php?title=ADTS
     **/
    public class AACDemuxer implements Demuxer {
        /** ADTS Syncword (0xFFF), ID:0 (MPEG4), layer (00) and protection_absent (1:no CRC).**/
        private static const SYNCWORD : uint = 0xFFF1;
        /** ADTS Syncword (0xFFF), ID:1 (MPEG2), layer (00) and protection_absent (1: no CRC).**/
        private static const SYNCWORD_2 : uint = 0xFFF9;
        /** ADTS Syncword (0xFFF), ID:1 (MPEG2), layer (00) and protection_absent (0: CRC).**/
        private static const SYNCWORD_3 : uint = 0xFFF8;
        /** ADTS/ADIF sample rates index. **/
        private static const RATES : Array = [96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350];
