/// <summary> /// Reads the box properties from stream. /// </summary> /// <param name="reader">The binary reader with the stream.</param> protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader) { var offset = reader.Offset; this.RawBytes = reader.ReadBytes((int)this.Size); reader.GotoPosition(offset); this.ConfigurationVersion = reader.ReadByte(); this.AvcProfileIndication = reader.ReadByte(); this.AvcCompatibleProfiles = reader.ReadByte(); this.AvcLevelIndication = reader.ReadByte(); this.NaluLengthSize = (byte)(1 + (reader.ReadByte() & 3)); var numSequenceParameters = (byte)(reader.ReadByte() & 0x1f); for (uint i = 0; i < numSequenceParameters; i++) { var length = reader.ReadUInt16(); this.SequenceParameters.Add(reader.ReadBytes(length)); } var numPictureParameters = reader.ReadByte(); for (uint j = 0; j < numPictureParameters; j++) { var length = reader.ReadUInt16(); this.PictureParameters.Add(reader.ReadBytes(length)); } }
/// <summary> /// This method of building the mfra will make web requests in order to download the data /// from the online source. /// </summary> /// <param name="callback">The action that should be notified when the process is complete.</param> private async Task ReadMovieFragmentRandomAccess() { #if !RANGESUFFIXSUPPORTED // not all backend services support range suffixes. For example, Azure Blobs. Here is a way around this but it requires an extra request to get the length and therefore does not perform as well. var fileSize = await WebRequestor.GetFileSizeAsync(this.fileUri); #endif // grab the mfra offset #if RANGESUFFIXSUPPORTED var offsetStream = await WebRequestor.GetStreamRangeAsync(this.fileUri, -4); #else var offsetStream = await WebRequestor.GetStreamRangeNoSuffixAsync(this.fileUri, -4, fileSize); #endif uint mfraOffset = 0; using (var reader = new BoxBinaryReader(offsetStream)) { mfraOffset = reader.ReadUInt32(); } // grab the mfra data #if RANGESUFFIXSUPPORTED var mfraStream = await WebRequestor.GetStreamRangeAsync(this.fileUri, -mfraOffset); #else var mfraStream = await WebRequestor.GetStreamRangeNoSuffixAsync(this.fileUri, -mfraOffset, fileSize); #endif // Write the bytes to our TOC file using (var reader = new BoxBinaryReader(mfraStream)) { reader.GotoPosition(0); Box box = null; do { box = reader.ReadNextBox(); if (box != null) { this.Boxes.Add(box); } } while (box != null); } }