public override void Write(BinaryWriter bw, int dataLen) { base.Write(bw, dataLen); bw.Write((UInt32)QBox.BE32(version)); bw.Write((UInt32)QBox.BE32(samplingFrequency)); bw.Write((UInt32)QBox.BE32(channels)); }
public virtual int Read(BinaryReader br) { int total = 0; boxSize = QBox.BE32(br.ReadUInt32()); total += 4; boxType = QBox.BE32(br.ReadUInt32()); total += 4; if (QMED_BOX_TYPE != boxType) { throw new Exception("Expecting a QMed, box type is incorrect"); } boxFlags.value = QBox.BE32(br.ReadUInt32()); total += 4; majorMediaType = QBox.BE32(br.ReadUInt32()); total += 4; if (majorMediaType != expectedMediaType) { throw new Exception("Media type is not as expected"); } minorMediaType = QBox.BE32(br.ReadUInt32()); total += 4; if (boxFlags.version == 1) { hashSize = QBox.BE32(br.ReadUInt32()); total += 4; for (int i = 0; i < (int)hashSize; i++) { hashPayload[i] = QBox.BE32(br.ReadUInt32()); total += 4; } } return(total); }
public override int Read(BinaryReader br) { int total = base.Read(br); version = QBox.BE64(br.ReadUInt64()); total += 8; accessUnits = (uint)QBox.BE32(br.ReadUInt32()); total += 4; return(total); }
public override int Read(BinaryReader br) { int total = base.Read(br); version = QBox.BE32(br.ReadUInt32()); total += 4; samplingFrequency = (uint)QBox.BE32(br.ReadUInt32()); total += 4; channels = (uint)QBox.BE32(br.ReadUInt32()); total += 4; return(total); }
public override void Write(BinaryWriter bw, int dataLen) { base.Write(bw, dataLen); bw.Write((UInt32)QBox.BE32(sampleSize)); //sampleSize = (uint)QBox.BE32(br.ReadUInt32()); bw.Write((UInt32)QBox.BE32(audioSpecificConfigSize)); //audioSpecificConfigSize = (uint)QBox.BE32(br.ReadUInt32()); for (int i = 0; i < (2 * audioSpecificConfigSize); i++) { bw.Write(audioSpecificConfig[i]); // //audioSpecificConfig[i] = br.ReadByte(); } }
public byte[] GetH264Nalu() { Stream rawPayload = new MemoryStream(SliceBytes); BinaryReader br = new BinaryReader(rawPayload); // first, determine actual length of NALU (without trailing bytes) int totalSize = SliceBytes.Length; int strippedCount = 0; while (totalSize > 4) { ulong naluLen = QBox.BE32(br.ReadUInt32()); if (naluLen > 0UL) { rawPayload.Position += (long)naluLen; // don't read yet, just advance } int totalNaluLen = (int)naluLen + 4; totalSize -= totalNaluLen; strippedCount += totalNaluLen; } // use actual length to declare outut array of bytes byte[] outBytes = new byte[strippedCount]; // reset Position of memory stream rawPayload.Position = 0; // get rid of trailing bytes, if any // at the same time, convert to bit stream totalSize = SliceBytes.Length; int offset = 0; int naluCount = 0; while (totalSize > 4) { ulong naluLen = QBox.BE32(br.ReadUInt32()); totalSize -= 4; if (naluLen > 0UL) { int readLen = (int)naluLen; outBytes[offset + 3] = (byte)1; // assume that outBytes[offset] to outBytes[offset + 2] are zero. offset += 4; rawPayload.Read(outBytes, offset, readLen); offset += readLen; totalSize -= readLen; } else { naluLen = 0; // debugging break point } naluCount++; } // end of while return(outBytes); }
public virtual void Write(BinaryWriter bw, int dataLen) { // this method must be called AFTER boxSize has been adjusted by derived object bw.Write((Int32)QBox.BE32(boxSize)); bw.Write((Int32)QBox.BE32(boxType)); bw.Write((Int32)QBox.BE32(boxFlags.value)); bw.Write((Int32)QBox.BE32(majorMediaType)); bw.Write((Int32)QBox.BE32(minorMediaType)); if (boxFlags.version == 1) { bw.Write((Int32)QBox.BE32(hashSize)); for (int i = 0; i < (int)hashSize; i++) { bw.Write((Int32)QBox.BE32(hashPayload[i])); } } }
public override Slice GetSample(StreamDataBlockInfo SampleInfo) { int delimiterLength = 0; Slice ans = new Slice(); ans.Copy(SampleInfo); ans.SliceBytes = new byte[SampleInfo.SliceSize]; #if REMOVE_EXTRA_SPS NaluDelimiterBlockInfo blockInfo = SampleInfo as NaluDelimiterBlockInfo; if (blockInfo.AccessUnitDelimiter != null) { delimiterLength = blockInfo.AccessUnitDelimiter.Length + 4; // access unit delimiter length is always 2 ans.SliceBytes[3] = (byte)(delimiterLength - 4); // assume that SliceBytes[0 to 2] are all zeroes, we only need to set LSB blockInfo.AccessUnitDelimiter.CopyTo(ans.SliceBytes, 4); } #endif //ParentStream.Stream.Position = (long)SampleInfo.StreamOffset; // remove empty NALUs (length == 0) // also remove trailing bytes, if any, from each NALU Slice inSlice = SampleInfo as Slice; BinaryReader br = new BinaryReader(new MemoryStream(inSlice.SliceBytes)); //BinaryReader br = new BinaryReader(ParentStream.Stream); int totalSize = SampleInfo.SliceSize - delimiterLength; int offset = delimiterLength; while (totalSize > 4) { ulong naluLen = QBox.BE32(br.ReadUInt32()); if (naluLen > 0UL) { br.BaseStream.Position -= 4; int readLen = (int)naluLen + 4; br.Read(ans.SliceBytes, offset, readLen); offset += readLen; totalSize -= readLen; } else { naluLen = 0; // debugging break point } } return(ans); }
public override int Read(BinaryReader br) { int total = base.Read(br); sampleSize = (uint)QBox.BE32(br.ReadUInt32()); total += 4; audioSpecificConfigSize = (uint)QBox.BE32(br.ReadUInt32()); total += 4; audioSpecificConfig = new byte[audioSpecificConfigSize * 2]; for (int i = 0; i < (2 * audioSpecificConfigSize); i++) { audioSpecificConfig[i] = br.ReadByte(); total += 1; } #if ADTS payloadSize -= (int)boxSize; payloadSize += 7; // get samplerate, channels and audio coding informations from QMED header int objectType = audioSpecificConfig[0] >> 3; int samplingFrequencyIndex = ((audioSpecificConfig[0] & 0x07) << 1) | ((audioSpecificConfig[1] & 0x80) >> 7); int channelConfiguration = (audioSpecificConfig[1] & 0x78) >> 3; adtsHeader = new byte[7]; adtsHeader[0] = 0xFF; adtsHeader[1] = 0xF0; adtsHeader[1] |= 0x1; adtsHeader[2] = (byte)(((objectType - 1) << 6) & 0xFF); // 0x40 for AAC-LC adtsHeader[2] |= (byte)(samplingFrequencyIndex << 2); adtsHeader[3] = (byte)(channelConfiguration << 6); adtsHeader[3] |= (byte)((payloadSize & 0x1800) >> 11); adtsHeader[4] = (byte)((payloadSize & 0x07f8) >> 3); adtsHeader[5] = (byte)((payloadSize & 0x0007) << 5); adtsHeader[5] |= 0x1F; adtsHeader[6] = 0xFC; #endif return(total); }