/// <summary> /// Load the entire partition from disk (when not yet loaded) /// </summary> public void Load() { if (!this.IsLoaded) { MXFKLVFactory klvFactory = new MXFKLVFactory(); using (MXFReader reader = new MXFReader(this.File.Filename)) { // Seek just after this partition reader.Seek(this.DataOffset + this.Length); while (!reader.EOF) { MXFKLV klv = klvFactory.CreateObject(reader, this); if (klv.Key.Type == KeyType.Partition || klv.Key.Type == KeyType.RIP || klv.Key.Type == KeyType.PrimerPack) { break; // Next partition or other segment, quit reading } if (!this.Children.Any(a => a.Offset == klv.Offset)) { // Normal, just add the new child this.AddChild(klv); } // Next KLV please reader.Seek(klv.DataOffset + klv.Length); } } this.IsLoaded = true; } }
public MXFMetadataBaseclass(MXFReader reader, MXFKLV headerKLV) : base(headerKLV, "MetaData", KeyType.MetaData) { this.m_eType = MXFObjectType.Meta; this.MetaDataName = "<unknown>"; Initialize(reader); }
/// <summary> /// Constructor, set the correct descriptor name /// </summary> /// <param name="reader"></param> /// <param name="headerKLV"></param> public MXFFileDescriptor(MXFReader reader, MXFKLV headerKLV) : base(reader, headerKLV, "Descriptor") { if (m_metaTypes.ContainsKey(this.Key[14])) { this.MetaDataName = m_metaTypes[this.Key[14]]; } }
public MXFMetadataBaseclass(MXFReader reader, MXFKLV headerKLV, string metaDataName) : base(headerKLV, "MetaData", KeyType.MetaData) { this.m_eType = MXFObjectType.Meta; this.MetaDataName = metaDataName; this.Key.Name = metaDataName; // TODO Correct?? Initialize(reader); }
/// <summary> /// Copy constructor /// </summary> /// <param name="reader"></param> public MXFKLV(MXFKLV klv) { this.Offset = klv.Offset; this.Key = klv.Key; this.Length = klv.Length; this.DataOffset = klv.DataOffset; this.Partition = klv.Partition; }
public MXFDescriptiveFramework(MXFReader reader, MXFKLV headerKLV) : base(reader, headerKLV, "DM Framework: <unknown>") { UInt16 setKey = (UInt16)((((UInt16)headerKLV.Key[13]) << 8) + ((UInt16)headerKLV.Key[14])); if (m_FWNames.ContainsKey(setKey)) { this.MetaDataName = string.Format("DM Framework: {0}", m_FWNames[setKey]); } }
public MXFANCFrameElement(MXFReader reader, MXFKLV headerKLV) : base(reader, headerKLV) { UInt16 nofPackets = reader.ReadUInt16(); for(int n = 0; n < nofPackets; n++) { MXFANCPacket newpacket = new MXFANCPacket(reader); this.AddChild(newpacket); } }
/// <summary> /// Returns true if the parent is a specific type /// </summary> /// <param name="type"></param> /// <returns></returns> public bool IsParentOfType(KeyType type) { MXFKLV klvParent = this.Parent as MXFKLV; if (klvParent == null) { return(false); } return(klvParent.Key.Type == type); }
/// <summary> /// Copy constructor /// </summary> /// <param name="reader"></param> public MXFKLV(MXFKLV klv, string name, KeyType type) { this.Offset = klv.Offset; this.Key = klv.Key; this.Key.Name = name; this.Key.Type = type; this.Length = klv.Length; this.DataOffset = klv.DataOffset; this.Partition = klv.Partition; }
public MXFSystemItem(MXFReader reader, MXFKLV headerKLV) : base(headerKLV, "SystemItem (CP)", KeyType.SystemItem) { this.m_eType = MXFObjectType.SystemItem; if (this.Key[12] == 0x14) { this.Key.Name = "SystemItem (GC)"; } reader.Seek(this.DataOffset); // Seek to the start of the data // Parse system bitmap this.SystemBitmap = (SystemBitmap)reader.ReadByte(); // Parse Content package rate byte rate = reader.ReadByte(); int rateIndex = (rate & 0x1E) >> 1; int[] rates = new int[16] { 0, 24, 25, 30, 48, 50, 60, 72, 75, 90, 96, 100, 120, 0, 0, 0 }; int rateNonDrop = 1; if (rateIndex < 16) { rateNonDrop = rates[rateIndex]; } this.PackageRate = rateNonDrop; if ((rate & 0x01) == 0x01) // 1.001 divider active? { this.PackageRate = this.PackageRate / 1.001; } // Parse Content Package Type byte type = reader.ReadByte(); this.StreamStatus = (SystemStreamStatus)((type & 0xE0) >> 5); this.LowLatencyMode = ((type & 0x10) == 0x10); this.TransferMode = (SystemTransferMode)((type & 0x0C) >> 2); this.TimingMode = (SystemTimingMode)(type & 0x03); this.ChannelHandle = reader.ReadUInt16(); this.ContinuityCount = reader.ReadUInt16(); this.SMPTE = reader.ReadULKey(); // Always read even if zero MXFTimeStamp creationTimeStamp = reader.ReadBCDTimeCode(this.PackageRate); this.CreationDate = creationTimeStamp.ToString(); this.UserDate = reader.ReadBCDTimeCode(this.PackageRate); this.UserDateFullFrameNb = this.UserDate.GetString(true); }
/// <summary> /// Locate all index table segments RECURSIVELY /// </summary> /// <param name="current"></param> public void FindIndexTableAndSystemItems(MXFObject current) { // LOAD the object (when not yet loaded) // This may take some time!!! if (current is ILazyLoadable loadable) { loadable.Load(); } MXFKLV klv = current as MXFKLV; if (klv != null) { if (klv.Key.Type == KeyType.IndexSegment) { MXFIndexTableSegment its = klv as MXFIndexTableSegment; if (its != null) { this.m_indexTables.Add(its); } } else if (klv.Key.Type == KeyType.SystemItem) { MXFSystemItem si = klv as MXFSystemItem; if (si != null) { si.Indexed = false; this.m_systemItems.Add(si); } } else if (klv.Key.Type == KeyType.Essence) { MXFEssenceElement ee = klv as MXFEssenceElement; if (ee != null) { if (ee.IsPicture) { ee.Indexed = false; this.m_pictureItems.Add(ee); } } } } if (!current.Children.Any()) { return; } foreach (MXFObject child in current.Children) { FindIndexTableAndSystemItems(child); } }
/// <summary> /// Constructor, set the correct descriptor name /// </summary> /// <param name="reader"></param> /// <param name="headerKLV"></param> public MXFGenericDataEssenceDescriptor(MXFReader reader, MXFKLV headerKLV) : base(reader, headerKLV, "Generic Data Essence Descriptor") { if (headerKLV.Key[14] == 0x5B) { this.Key.Name = "VBI Data Descriptor"; } if (headerKLV.Key[14] == 0x5C) { this.Key.Name = "ANC Data Descriptor"; } this.MetaDataName = this.Key.Name; }
/// <summary> /// Constructor, set the correct descriptor name /// </summary> /// <param name="reader"></param> /// <param name="headerKLV"></param> public MXFGenericDataEssenceDescriptor(MXFReader reader, MXFKLV headerKLV) : base(reader, headerKLV, "Generic Data Essence Descriptor") { // TODO remove code, once implemented the subclasses if (headerKLV.Key[14] == 0x5B) { this.Key.Name = "VBI Data Descriptor"; } if (headerKLV.Key[14] == 0x5C) { this.Key.Name = "ANC Data Descriptor"; } this.MetaDataName = this.Key.Name; }
/// <summary> /// Create a new MXF object based on the KLV key /// </summary> /// <param name="reader"></param> /// <param name="currentPartition"></param> /// <returns></returns> public MXFKLV CreateObject(MXFReader reader, MXFPartition currentPartition) { MXFKLV klv = new MXFKLV(reader); klv.Partition = currentPartition; // Pass the current partition through to the classes if (dict.TryGetValue(klv.Key, out Type foundType)) { return((MXFKLV)Activator.CreateInstance(foundType, reader, klv)); } else { // TODO what if the key cannot be found, i.e. it is not known? } return(klv); }
public MXFEssenceElement(MXFReader reader, MXFKLV headerKLV) : base(headerKLV, "EssenceElement", KeyType.Essence) { this.m_eType = MXFObjectType.Essence; if (m_itemTypes.ContainsKey(this.Key[12])) { this.ItemType = m_itemTypes[this.Key[12]]; } else { this.ItemType = "<unknown>"; } this.IsPicture = (this.Key[12] == 0x05 || this.Key[12] == 0x15); this.ElementCount = this.Key[13]; this.ElementType = this.Key[14]; this.ElementNumber = this.Key[15]; }
public MXFPartition(MXFReader reader, MXFKLV headerKLV) : base(headerKLV, "Partition", KeyType.Partition) { this.m_eType = MXFObjectType.Partition; this.IsLoaded = false; // Determine the partition type switch (this.Key[13]) { case 2: this.PartitionType = PartitionType.Header; break; case 3: this.PartitionType = PartitionType.Body; break; case 4: this.PartitionType = PartitionType.Footer; break; default: this.PartitionType = PartitionType.Unknown; Log(MXFLogType.Error, "unknown partition type"); break; } this.Closed = (this.PartitionType == PartitionType.Footer) || (this.Key[14] & 0x01) == 0x00; this.Complete = (this.Key[14] > 2); // Make sure we read at the data position reader.Seek(this.DataOffset); this.MajorVersion = reader.ReadUInt16(); this.MinorVersion = reader.ReadUInt16(); this.KagSize = reader.ReadUInt32(); this.ThisPartition = reader.ReadUInt64(); this.PreviousPartition = reader.ReadUInt64(); this.FooterPartition = reader.ReadUInt64(); this.HeaderByteCount = reader.ReadUInt64(); this.IndexByteCount = reader.ReadUInt64(); this.IndexSID = reader.ReadUInt32(); this.BodyOffset = reader.ReadUInt64(); this.BodySID = reader.ReadUInt32(); this.OP = reader.ReadULKey(); MXFObject essenceContainers = reader.ReadAUIDSet("Essence Containers", "Essence Container"); this.AddChild(essenceContainers); }
public MXFPackageMetaData(MXFReader reader, MXFKLV headerKLV) : base(headerKLV, "PackageMetadata", KeyType.PackageMetaDataSet) { this.m_eType = MXFObjectType.Essence; // I will count this as essence data if (this.Key[5] == 0x63) { nofSizeSize = 4; } switch (this.Key[14]) { case 0x02: this.Key.Name = "Package Metadata set"; break; case 0x03: this.Key.Name = "Picture Metadata set"; break; case 0x04: this.Key.Name = "Sound Metadata set"; break; case 0x05: this.Key.Name = "Data Metadata set"; break; case 0x06: this.Key.Name = "Control Metadata set"; break; } reader.Seek(this.DataOffset); // Seek to the start of the data long end = this.DataOffset + this.Length; while (reader.Position < end) { byte type = reader.ReadB(); UInt32 size = 0; if (nofSizeSize == 2) { size = reader.ReadW(); } else { size = reader.ReadD(); } long startPos = reader.Position; if (m_itemTypes.ContainsKey(type)) { this.AddChild(new MXFData(m_itemTypes[type], reader, size)); } reader.Seek(startPos + size); } }
/// <summary> /// Create a new MXF object based on the KLV key /// </summary> /// <param name="reader"></param> /// <param name="currentPartition"></param> /// <returns></returns> public MXFKLV CreateObject(MXFReader reader, MXFPartition currentPartition) { MXFKLV klv = new MXFKLV(reader); klv.Partition = currentPartition; // Pass the current partition through to the classes foreach (MXFKey knownKey in MXFKLVFactory.m_allKeys) { if (klv.Key == knownKey) { if (knownKey.ObjectType != null) { return((MXFKLV)Activator.CreateInstance(knownKey.ObjectType, reader, klv)); } klv.Key.Name = knownKey.Name; klv.Key.Type = knownKey.Type; break; } } return(klv); }
/// <summary> /// Try to locate the RIP /// </summary> private bool ReadRIP(MXFKLVFactory klvFactory) { if (this.RIP == null) { // Read the last 4 bytes of the file m_reader.Seek(this.Filesize - 4); uint ripSize = m_reader.ReadD(); if (ripSize < this.Filesize && ripSize >= 4) // At least 4 bytes { m_reader.Seek(this.Filesize - ripSize); MXFKLV klv = klvFactory.CreateObject(m_reader, null); if (klv.Key.Type == KeyType.RIP) { // Yes, RIP found this.AddChild(klv); this.RIP = klv as MXFRIP; return(true); } } } return(false); }
public MXFPackageMetaData(MXFReader reader, MXFKLV headerKLV) : base(headerKLV, "PackageMetadata", KeyType.PackageMetaDataSet) { this.m_eType = MXFObjectType.Essence; // I will count this as essence data if (this.Key[5] == 0x63) { nofSizeSize = 4; } switch (this.Key[14]) { case 0x02: this.Key.Name = "Package Metadata set"; break; case 0x03: this.Key.Name = "Picture Metadata set"; break; case 0x04: this.Key.Name = "Sound Metadata set"; break; case 0x05: this.Key.Name = "Data Metadata set"; break; case 0x06: this.Key.Name = "Control Metadata set"; break; } ParseElements(reader); }
public MXFIdentification(MXFReader reader, MXFKLV headerKLV) : base(reader, headerKLV, "Identification") { }
public MXFDynamicMarker(MXFReader reader, MXFKLV headerKLV) : base(reader, headerKLV) { this.MetaDataName = "DynamicMarker"; }
/// <summary> /// Constructor when used as base class /// </summary> /// <param name="reader"></param> /// <param name="headerKLV"></param> public MXFAIFCDescriptor(MXFReader reader, MXFKLV headerKLV) : base(reader, headerKLV, "AIFCDescriptor") { }
public MXFEvent(MXFReader reader, MXFKLV headerKLV, string metadataName) : base(reader, headerKLV, "Event") { }
public MXFAddress(MXFReader reader, MXFKLV headerKLV) : base(reader, headerKLV) { this.MetaDataName = "Address"; }
public MXFProductionClipFramework(MXFReader reader, MXFKLV headerKLV) : base(reader, headerKLV) { this.MetaDataName = "ProductionClipFramework"; }
public MXFTaggedValue(MXFReader reader, MXFKLV headerKLV) : base(reader, headerKLV, "TaggedValue") { }
public MXFTypeDefinitionExtendibleEnumeration(MXFReader reader, MXFKLV headerKLV) : base(reader, headerKLV) { this.MetaDataName = "TypeDefinitionExtendibleEnumeration"; }
public MXFGenericTrack(MXFReader reader, MXFKLV headerKLV) : base(reader, headerKLV, "Generic Track") { }
public MXFGenericTrack(MXFReader reader, MXFKLV headerKLV, string metadataName) : base(reader, headerKLV, metadataName) { }