/// <summary> /// Constructs a <see cref="Track" /> parsing from provided /// file data. /// Parsing will be done reading from _file at position references by /// parent element's data section. /// </summary> /// <param name="_file"><see cref="File" /> instance to read from.</param> /// <param name="element">Parent <see cref="EBMLElement" />.</param> public Track(File _file, EBMLElement element) { ulong i = 0; while (i < element.DataSize) { EBMLElement child = new EBMLElement(_file, element.DataOffset + i); MatroskaID matroska_id = (MatroskaID)child.ID; switch (matroska_id) { case MatroskaID.MatroskaTrackNumber: track_number = child.ReadUInt(); break; case MatroskaID.MatroskaTrackUID: track_uid = child.ReadUInt(); break; case MatroskaID.MatroskaCodecID: track_codec_id = child.ReadString(); break; case MatroskaID.MatroskaCodecName: track_codec_name = child.ReadString(); break; case MatroskaID.MatroskaTrackName: track_name = child.ReadString(); break; case MatroskaID.MatroskaTrackLanguage: track_language = child.ReadString(); break; case MatroskaID.MatroskaTrackFlagEnabled: track_enabled = child.ReadBool(); break; case MatroskaID.MatroskaTrackFlagDefault: track_default = child.ReadBool(); break; case MatroskaID.MatroskaCodecPrivate: codec_data = child.ReadBytes(); break; default: unknown_elems.Add(child); break; } i += child.Size; } }
private void ReadSimpleTag(EBMLElement element) { ulong i = 0; #pragma warning disable 219 // Assigned, never read string tag_name = null, tag_language = null, tag_string = null; #pragma warning restore 219 while (i < element.DataSize) { EBMLElement child = new EBMLElement(this, element.DataOffset + i); MatroskaID matroska_id = (MatroskaID)child.ID; switch (matroska_id) { case MatroskaID.MatroskaTagName: tag_name = child.ReadString(); break; case MatroskaID.MatroskaTagLanguage: tag_language = child.ReadString(); break; case MatroskaID.MatroskaTagString: tag_string = child.ReadString(); break; default: break; } i += child.Size; } if (tag_name == "AUTHOR") { tag.Performers = new string[] { tag_string }; } else if (tag_name == "TITLE") { tag.Title = tag_string; } else if (tag_name == "ALBUM") { tag.Album = tag_string; } else if (tag_name == "COMMENTS") { tag.Comment = tag_string; } }
private void ReadHeader(EBMLElement element) { string doctype = null; ulong i = 0; while (i < element.DataSize) { EBMLElement child = new EBMLElement(this, element.DataOffset + i); EBMLID ebml_id = (EBMLID)child.ID; switch (ebml_id) { case EBMLID.EBMLDocType: doctype = child.ReadString(); break; default: break; } i += child.Size; } // Check DocType if (String.IsNullOrEmpty(doctype) || (doctype != "matroska" && doctype != "webm")) { throw new UnsupportedFormatException("DocType is not matroska or webm"); } }
private void ReadSegmentInfo(EBMLElement element) { ulong i = 0; while (i < element.DataSize) { EBMLElement child = new EBMLElement(this, element.DataOffset + i); MatroskaID matroska_id = (MatroskaID)child.ID; switch (matroska_id) { case MatroskaID.MatroskaDuration: duration_unscaled = (UInt64)child.ReadDouble(); if (time_scale > 0) { duration = TimeSpan.FromSeconds(duration_unscaled * time_scale / 1000000000); } break; case MatroskaID.MatroskaTimeCodeScale: time_scale = child.ReadUInt(); if (duration_unscaled > 0) { duration = TimeSpan.FromSeconds(duration_unscaled * time_scale / 1000000000); } break; case MatroskaID.MatroskaTitle: title = child.ReadString(); break; default: break; } i += child.Size; } }