/// <summary> /// Read the cues from the root cue node. /// </summary> public static Cue[] GetCues(MatroskaSegment segment, Stream reader) { MatroskaTree cues = segment.GetChildFromSeek(reader, MatroskaTree.Segment_Cues); if (cues == null) { return(new Cue[0]); } segment.Position(reader); long offset = reader.Position; MatroskaTree[] sources = cues.GetChildren(reader, MatroskaTree.Segment_Cues_CuePoint); Cue[] results = new Cue[sources.Length]; for (int i = 0; i < sources.Length; ++i) { long time = sources[i].GetChildValue(reader, MatroskaTree.Segment_Cues_CuePoint_CueTime); MatroskaTree position = sources[i].GetChild(reader, MatroskaTree.Segment_Cues_CuePoint_CueTrackPositions); results[i] = new Cue( time, position.GetChildValue(reader, MatroskaTree.Segment_Cues_CuePoint_CueTrackPositions_CueTrack), offset + position.GetChildValue(reader, MatroskaTree.Segment_Cues_CuePoint_CueTrackPositions_CueClusterPosition) ); } return(results); }
/// <summary> /// Reads the segment with its seek header. /// </summary> public MatroskaSegment(Stream reader) : base(reader) { MatroskaTree seekHead = GetChild(reader, Segment_SeekHead); if (seekHead == null) { reader.Position = end; return; } MatroskaTree[] seekInputs = seekHead.GetChildren(reader, Segment_SeekHead_Seek); for (int i = 0; i < seekInputs.Length; ++i) { seeks[(int)seekInputs[i].GetChildValue(reader, Segment_SeekHead_Seek_SeekID)] = seekInputs[i].GetChildValue(reader, Segment_SeekHead_Seek_SeekPosition); } reader.Position = end; }
/// <summary> /// All blocks of the cluster, in order. /// </summary> public IReadOnlyList <Block> GetBlocks(Stream reader) { if (blocks != null) { return(blocks); } MemoryStream stream = new MemoryStream(source.GetRawData(reader)); blocks = new List <Block>(); long end = stream.Length - 2; // Safety barrier, a byte might remain, but a 2 byte child is impossible while (stream.Position < end) { MatroskaTree child = new MatroskaTree(stream); long continueFrom = stream.Position; // Block groups (Matroska v1) if (child.Tag == MatroskaTree.Segment_Cluster_BlockGroup) { MatroskaTree[] blocksHere = child.GetChildren(stream, MatroskaTree.Segment_Cluster_BlockGroup_Block); for (int i = 0; i < blocksHere.Length; ++i) { blocks.Add(new Block(stream, blocksHere[i])); } } // Simple blocks (Matroska v2) else if (child.Tag == MatroskaTree.Segment_Cluster_SimpleBlock) { blocks.Add(new Block(stream, child)); } stream.Position = continueFrom; } return(blocks); }