/// <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> /// 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> /// Reads the sample entry properties from stream. /// </summary> /// <param name="reader">The stream reader.</param> internal override void ReadSampleEntryPropertiesFromStream(BoxBinaryReader reader) { predefined1 = reader.ReadUInt16(); reserved1 = reader.ReadUInt16(); predefined2 = reader.ReadBytes(12); this.Width = reader.ReadUInt16(); this.Height = reader.ReadUInt16(); this.HorizResolution = reader.ReadUInt32(); this.VertResolution = reader.ReadUInt32(); reserved2 = reader.ReadUInt32(); this.FrameCount = reader.ReadUInt16(); byte[] buffer = new byte[0x20]; reader.Read(buffer, 0, 0x20); int count = buffer[0]; if (count < 0x20) { this.CompressorName = Encoding.UTF8.GetString(buffer, 1, count); } this.Depth = reader.ReadUInt16(); predefined3 = reader.ReadUInt16(); if (reader.PeekNextBoxType() != BoxType.Null) { ReadInnerBoxes(reader, BoxType.Esds, BoxType.Avcc, BoxType.Avc1, BoxType.Dvc1, BoxType.Btrt, BoxType.Sinf); this.VideoCodecData = GetVideoCodecDataFromInnerBoxes(); } else { var videoInfoHeader = new VideoInfoHeader2(reader); this.VideoCodecData = new VideoTrackCodecData(videoInfoHeader); } }
/// <summary> /// Reads the box properties from stream. /// </summary> /// <param name="reader">The binary reader with the stream.</param> protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader) { this.reserved = reader.ReadBytes(6); this.DataReferenceIndex = reader.ReadUInt16(); ReadSampleEntryPropertiesFromStream(reader); }
/// <summary> /// Reads the box properties from stream. /// </summary> /// <param name="reader">The binary reader with the stream.</param> protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader) { this.reserved = reader.ReadBytes(6); this.DataReferenceIndex = reader.ReadUInt16(); ReadSampleEntryPropertiesFromStream(reader); }
/// <summary> /// Reads the full box properties from stream. /// </summary> /// <param name="reader">The binary reader with the stream.</param> protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader) { this.SystemId = reader.ReadGuid(); if (string.Compare(this.SystemId.ToString(), "9A04F079-9840-4286-AB92-E65BE0885F95", StringComparison.OrdinalIgnoreCase) != 0) { throw new BoxException(string.Format("The specified protection system id \"{0}\" is not supported", this.SystemId)); } this.DataSize = reader.ReadUInt32(); this.Data = reader.ReadBytes(System.Convert.ToInt32(this.DataSize)); }
/// <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 num = reader.ReadByte(); this.Profile = (num >> 6); this.Level = (num & 0xF) >> 1; this.AdvancedProfileLevel = reader.ReadByte() >> 5; this.flags = reader.ReadByte(); //no_interlace, no_multiple_seq, no_multiple_entry, no_slice_code, no_bframe this.Framerate = reader.ReadUInt32(); this.CodecPrivateData = reader.ReadBytes((int)(this.Size - (reader.Offset - this.Offset))); }
/// <summary> /// Reads the full box properties from stream. /// </summary> /// <param name="reader">The binary reader with the stream.</param> protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader) { this.SystemId = reader.ReadGuid(); if (string.Compare(this.SystemId.ToString(), "9A04F079-9840-4286-AB92-E65BE0885F95", StringComparison.OrdinalIgnoreCase) != 0) { throw new BoxException(string.Format("The specified protection system id \"{0}\" is not supported", this.SystemId)); } this.DataSize = reader.ReadUInt32(); this.Data = reader.ReadBytes(System.Convert.ToInt32(this.DataSize)); }
/// <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 num = reader.ReadByte(); this.Profile = (num >> 6); this.Level = (num & 0xF) >> 1; this.AdvancedProfileLevel = reader.ReadByte() >> 5; this.flags = reader.ReadByte(); //no_interlace, no_multiple_seq, no_multiple_entry, no_slice_code, no_bframe this.Framerate = reader.ReadUInt32(); this.CodecPrivateData = reader.ReadBytes((int)(this.Size - (reader.Offset - this.Offset))); }
/// <summary> /// Initializes a new instance of the <see cref="WaveFormatEx"/> class. /// </summary> /// <param name="reader">The binary stream reader.</param> public WaveFormatEx(BoxBinaryReader reader) { this.FormatTag = reader.ReadInt16(); this.Channels = reader.ReadInt16(); this.SamplesPerSec = reader.ReadInt32(); this.AvgBytesPerSec = reader.ReadInt32(); ; this.BlockAlign = reader.ReadInt16(); this.BitsPerSample = reader.ReadInt16(); this.Size = reader.ReadInt16(); if (this.Size > 0) { this.ExtendedData = reader.ReadBytes(this.Size); } }
/// <summary> /// Initializes a new instance of the <see cref="WaveFormatEx"/> class. /// </summary> /// <param name="reader">The binary stream reader.</param> public WaveFormatEx(BoxBinaryReader reader) { this.FormatTag = reader.ReadInt16(); this.Channels = reader.ReadInt16(); this.SamplesPerSec = reader.ReadInt32(); this.AvgBytesPerSec = reader.ReadInt32();; this.BlockAlign = reader.ReadInt16(); this.BitsPerSample = reader.ReadInt16(); this.Size = reader.ReadInt16(); if (this.Size > 0) { this.ExtendedData = reader.ReadBytes(this.Size); } }
/// <summary> /// Reads the box properties from stream. /// </summary> /// <param name="reader">The binary reader with the stream.</param> protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader) { if ((this.Flags & 1) != 0) { this.AuxInfoType = reader.ReadUInt32(); this.AuxInfoTypeParameter = reader.ReadUInt32(); } this.DefaultSampleInfoSize = reader.ReadByte(); this.SampleCount = reader.ReadUInt32(); if (this.DefaultSampleInfoSize == 0) { this.SampleInfoSize = reader.ReadBytes(System.Convert.ToInt32(this.SampleCount)); } }
/// <summary> /// Reads the box properties from stream. /// </summary> /// <param name="reader">The binary reader with the stream.</param> protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader) { if ((this.Flags & 1) != 0) { this.AuxInfoType = reader.ReadUInt32(); this.AuxInfoTypeParameter = reader.ReadUInt32(); } this.DefaultSampleInfoSize = reader.ReadByte(); this.SampleCount = reader.ReadUInt32(); if (this.DefaultSampleInfoSize == 0) { this.SampleInfoSize = reader.ReadBytes(System.Convert.ToInt32(this.SampleCount)); } }
/// <summary> /// Gets a fragment of track data from the file that is being streamed locally. /// </summary> /// <param name="trackType">The type of track being requested (video, audio, text)</param> /// <param name="bitrate">The bitrate of the track that should be returned.</param> /// <param name="timeOffset">The time offset of the fragment of data being requested.</param> /// <param name="language">The ISO language code of the track if there is one.</param> /// <param name="callback">The callback that will be invoked when the fragment has been retrieved. /// The callback will have the stream to the data.</param> /// <remarks>The fragment that will be returned will be a moof and mdat pair of boxes from the file.</remarks> public override async Task <WebRequestorResponse> GetTrackFragmentStream(ManifestTrackType trackType, uint bitrate, ulong timeOffset, string language) { if (language == string.Empty) { language = null; } var track = this.ManifestTracks .Where(t => t.Type == trackType && t.Bitrate == bitrate && t.Language == language) .SingleOrDefault(); if (track != null) { var entry = track.Fragments.TrackFragmentRandomAccessEntries.FirstOrDefault(e => e.Time == timeOffset); if (entry != null) { ulong moofSize = 0; ulong mdatSize = 0; long moofOffset = 0; using (var fileStream = await StorageFile.OpenStreamForReadAsync()) { var reader = new BoxBinaryReader(fileStream); moofOffset = (long)entry.MoofOffset; reader.BaseStream.Seek(moofOffset, SeekOrigin.Begin); moofSize = this.ReadBoxSize(reader); // Run to the end of the moof to get to its mdat box reader.BaseStream.Seek(moofOffset + (long)moofSize, SeekOrigin.Begin); mdatSize = this.ReadBoxSize(reader); // And back to the beginning of the moof so we can read both boxes into the stream reader.BaseStream.Seek(moofOffset, SeekOrigin.Begin); var size = moofSize + mdatSize; var fragment = reader.ReadBytes((int)size); var stream = new MemoryStream(fragment); return(new WebRequestorResponse(stream, System.Net.HttpStatusCode.OK, null, string.Empty)); } } } throw new WebRequestorFailure(System.Net.HttpStatusCode.NotFound, null); }
/// <summary> /// Initializes a new instance of the <see cref="BitmapInfonHeader"/> class. /// </summary> /// <param name="reader">The box binary reader.</param> public BitmapInfonHeader(BoxBinaryReader reader) { var initialOffset = reader.Offset; this.Size = reader.ReadInt32(); this.Width = reader.ReadInt32(); this.Height = reader.ReadInt32(); this.Planes = reader.ReadInt16(); this.BitCount = reader.ReadInt16(); this.Compression = reader.ReadString(4); this.ImageSize = reader.ReadInt32(); this.XPixelsPerMeter = reader.ReadInt32(); this.YPixelsPerMeter = reader.ReadInt32(); this.ColorsUsed = reader.ReadInt32(); this.ColorsImportant = reader.ReadInt32(); this.CodecPrivateData = reader.ReadBytes(this.Size - (int)(reader.Offset - initialOffset)); }
/// <summary> /// Reads the sample entry properties from stream. /// </summary> /// <param name="reader">The stream reader.</param> internal override void ReadSampleEntryPropertiesFromStream(BoxBinaryReader reader) { predefined1 = reader.ReadUInt16(); reserved1 = reader.ReadUInt16(); predefined2 = reader.ReadBytes(12); this.Width = reader.ReadUInt16(); this.Height = reader.ReadUInt16(); this.HorizResolution = reader.ReadUInt32(); this.VertResolution = reader.ReadUInt32(); reserved2 = reader.ReadUInt32(); this.FrameCount = reader.ReadUInt16(); byte[] buffer = new byte[0x20]; reader.Read(buffer, 0, 0x20); int count = buffer[0]; if (count < 0x20) { this.CompressorName = Encoding.UTF8.GetString(buffer, 1, count); } this.Depth = reader.ReadUInt16(); predefined3 = reader.ReadUInt16(); if (reader.PeekNextBoxType() != BoxType.Null) { ReadInnerBoxes(reader, BoxType.Esds, BoxType.Avcc, BoxType.Avc1, BoxType.Dvc1, BoxType.Btrt, BoxType.Sinf); this.VideoCodecData = GetVideoCodecDataFromInnerBoxes(); } else { var videoInfoHeader = new VideoInfoHeader2(reader); this.VideoCodecData = new VideoTrackCodecData(videoInfoHeader); } }
/// <summary> /// Reads the descriptor properties from stream. /// </summary> /// <param name="reader">The binary reader with the stream.</param> protected override void ReadDescriptorPropertiesFromStream(BoxBinaryReader reader) { this.Information = reader.ReadBytes((int)this.PayloadSize); }
/// <summary> /// Reads the descriptor properties from stream. /// </summary> /// <param name="reader">The binary reader with the stream.</param> protected override void ReadDescriptorPropertiesFromStream(BoxBinaryReader reader) { this.Information = reader.ReadBytes((int)this.PayloadSize); }