/// <summary> /// コンストラクタ /// </summary> /// <param name="offset">フレームのバイトオフセット</param> public AdtsFrameInfo(AacAdtsHeader hdr, long offset) { // 1 aac frame is 1024 samples // AAC files always have 1024 samples per frame. // In MP4 files it can be 960 too, // 1024 samples per frame, per channel Header = hdr; Offset = offset; Duration = 1024.0 / Header.SamplingRate; Bps = Header.FrameSize * 8 / Duration; }
/// <summary> /// ストリームパーシング処理本体 /// </summary> /// <param name="br">バイナリ読み込みオブジェクト</param> /// <param name="remain">読み取り可能なバイトサイズ</param> /// <returns></returns> private dynamic parse(BinaryReader br, long remain) { while (remain > 7) { // ヘッダー分読み込む long offset = br.BaseStream.Position; byte[] b = br.ReadBytes(7); var hdr = new AacAdtsHeader(); // Sync Header if (b[0] != 0xFF && (b[1] & 0xF0) != 0xF0) { System.Diagnostics.Debug.WriteLine("error"); return(new { Result = 1, Remain = remain }); } // ID hdr.ID = ((b[1] & 0x08) == 0x08); // Layer, 常に0 if ((b[1] & 0x06) != 0) { System.Diagnostics.Debug.WriteLine("error"); return(new { Result = 2, Remain = remain }); } // Protection bit hdr.ProtectionBit = ((b[1] & 0x01) == 0x01); // Profile hdr.Profile = (byte)((b[2] >> 6) & 0x03); // Fs hdr.Fs = (byte)((b[2] >> 2) & 0x0F); // PrivateBit hdr.PrivateBit = ((b[2] & 0x02) == 0x02); byte tmp = (byte)(b[2] & 0x01); tmp <<= 2; tmp |= (byte)((b[3] >> 6) & 0x3); hdr.Channel = tmp; // オリジナル hdr.Original = ((b[3] & 0x20) == 0x20); hdr.Home = ((b[3] & 0x10) == 0x10); hdr.Copyright = ((b[3] & 0x08) == 0x08); hdr.Icopyright = ((b[3] & 0x04) == 0x04); // フレームサイズ UInt16 size = (byte)(b[3] & 0x03); size <<= 8; size |= b[4]; size <<= 3; size |= (UInt16)(b[5] >> 5); hdr.FrameSize = (Int16)size; // バッファサイズ size = (byte)(b[5] & 0x1F); size <<= 6; size |= (UInt16)((b[6] >> 2) & 0x3F); hdr.BufferSize = (Int16)size; // オフセット hdr.DBOffset = (byte)(b[6] & 0x03); if (!hdr.ProtectionBit) { hdr.CRC = br.ReadUInt16(); } // 保存 AdtsFrameInfo fi = new AdtsFrameInfo(hdr, offset); m_List.Add(fi); // 移動 br.BaseStream.Seek(offset + hdr.FrameSize, SeekOrigin.Begin); remain -= hdr.FrameSize; } return(new { Result = 0, Remain = remain }); }