public AsfDataObjectItem(Stream stream) : base("Data Object", AsfGuid.ASF_Simple_Index_Object, stream) { AsfDataObject asfDataObject = new AsfDataObject(stream, Configuration); _packets = asfDataObject.Packets; }
private AsfDataObject parseDataObject(Stream inStream, long currentOffset) { AsfDataObject dataObject = new AsfDataObject(); dataObject.ObjectGuid = new Guid(ParseFile.ParseSimpleOffset(inStream, currentOffset, 0x10)); dataObject.ObjectSize = BitConverter.ToUInt64(ParseFile.ParseSimpleOffset(inStream, (currentOffset + 0x10), 8), 0); dataObject.FileGuid = new Guid(ParseFile.ParseSimpleOffset(inStream, currentOffset + 0x18, 0x10)); dataObject.TotalDataPackets = BitConverter.ToUInt64(ParseFile.ParseSimpleOffset(inStream, currentOffset + 0x28, 8), 0); dataObject.Reserved = BitConverter.ToUInt16(ParseFile.ParseSimpleOffset(inStream, currentOffset + 0x30, 2), 0); return(dataObject); }
public void EnumeratePackets() { AsfFile asfFile = new AsfFile(testVideoFileName); //Data Object returned from asfFile will not cover packets AsfDataObject asfDataObject = asfFile.GetAsfObject <AsfDataObject>(); //to retrieve packets we need to pass a full file stream into AsfDataObject using (FileStream fs = new FileStream(testVideoFileName, FileMode.Open, FileAccess.Read)) { fs.Seek(asfDataObject.Position, SeekOrigin.Begin); AsfDataObject asfDataObjectFull = new AsfDataObject(fs, asfFile.PacketConfiguration); } Assert.AreEqual(648, asfFile.PacketConfiguration.Packets.Count); }
public virtual void DemultiplexStreams(MpegStream.DemuxOptionsStruct demuxOptions) { long currentOffset = 0; long packetOffset = 0; long packetSize; long fileSize; Dictionary <uint, FileStream> streamOutputWriters = new Dictionary <uint, FileStream>(); Guid checkGuid; ulong blockSize; try { using (FileStream fs = File.OpenRead(this.FilePath)) { fileSize = fs.Length; currentOffset = 0; currentOffset = ParseFile.GetNextOffset(fs, 0, MicrosoftAsfContainer.ASF_HEADER_BYTES); if (currentOffset > -1) { while (currentOffset < fileSize) { // get guid checkGuid = new Guid(ParseFile.ParseSimpleOffset(fs, currentOffset, 0x10)); blockSize = BitConverter.ToUInt64(ParseFile.ParseSimpleOffset(fs, (currentOffset + 0x10), 8), 0); // process block if (checkGuid.Equals(MicrosoftAsfContainer.ASF_Header_Object)) { // parse header this.parseHeader(fs, currentOffset); } else if (checkGuid.Equals(MicrosoftAsfContainer.ASF_Data_Object)) { // parse data object this.DataObject = this.parseDataObject(fs, currentOffset); // process data packets packetOffset = currentOffset + 0x32; // header has been parsed for (ulong i = 0; i < this.DataObject.TotalDataPackets; i++) { // parse packet try { packetSize = this.parseDataPacket(fs, packetOffset, demuxOptions); // move to next packet if (packetSize < 0) { throw new Exception(String.Format("Error parsing data packet at offset 0x{0}.", packetOffset.ToString("X8"))); } else { packetOffset += packetSize; } } catch (Exception ex) { throw new Exception(String.Format("Error parsing data packet at offset 0x{0}: {1}.{2}", packetOffset.ToString("X8"), ex.Message, Environment.NewLine)); } } } // increment counter currentOffset += (long)blockSize; } // while } else { throw new Exception(String.Format("ASF/WMV Header not found.{0}", Environment.NewLine)); } } // using (FileStream fs = File.OpenRead(this.FilePath)) } catch (Exception ex) { throw new Exception(String.Format("Exception processing block at offset 0x{0}: {1}{2}", currentOffset.ToString("X"), ex.Message, Environment.NewLine)); } finally { // clean up this.DoFinalTasks(demuxOptions); } }
public void EnumeratePackets() { AsfFile asfFile = new AsfFile(testVideoFileName); //Data Object returned from asfFile will not cover packets AsfDataObject asfDataObject = asfFile.GetAsfObject<AsfDataObject>(); //to retrieve packets we need to pass a full file stream into AsfDataObject using (FileStream fs = new FileStream(testVideoFileName, FileMode.Open, FileAccess.Read)) { fs.Seek(asfDataObject.Position, SeekOrigin.Begin); AsfDataObject asfDataObjectFull = new AsfDataObject(fs, asfFile.PacketConfiguration); } Assert.AreEqual(648, asfFile.PacketConfiguration.Packets.Count); }