public Bitstream (Page page) { if (page == null) throw new ArgumentNullException ("page"); // Assume that the first packet is completely enclosed. This should be // sufficient for codec recognition. _codec = Codec.GetCodec (page.Packets [0]); _first_absolute_granular_position = page.Header.AbsoluteGranularPosition; }
public void AddPage (Page page) { pages_read ++; if (first_page_header == null) first_page_header = page.Header; if (page.Packets.Length == 0) return; ByteVector[] page_packets = page.Packets; for (int i = 0; i < page_packets.Length; i ++) { if ((page.Header.Flags & PageFlags .FirstPacketContinued) != 0 && i == 0 && packets.Count > 0) packets [packets.Count - 1].Add (page_packets [0]); else packets.Add (page_packets [i]); } }
public bool ReadPage (Page page) { if (page == null) throw new ArgumentNullException ("page"); ByteVector[] packets = page.Packets; for (int i = 0; i < packets.Length; i ++) { if ((page.Header.Flags & PageFlags.FirstPacketContinued) == 0 && _previous_packet != null) { if (ReadPacket (_previous_packet)) return true; _previous_packet = null; } ByteVector packet = packets [i]; // If we're at the first packet of the page, and we're continuing an // old packet, combine the old with the new. if (i == 0 && (page.Header.Flags & PageFlags.FirstPacketContinued) != 0 && _previous_packet != null) { _previous_packet.Add (packet); packet = _previous_packet; } _previous_packet = null; // If we're at the last packet of the page, store it. if (i == packets.Length - 1) _previous_packet = new ByteVector (packet); // Otherwise, we need to process it. else if (ReadPacket (packet)) return true; } return false; }
private Dictionary<uint, Bitstream> ReadStreams (List<Page> pages, out long end) { Dictionary<uint, Bitstream> streams = new Dictionary<uint, Bitstream> (); List<Bitstream> active_streams = new List<Bitstream> (); long position = 0; do { Bitstream stream = null; Page page = new Page (this, position); if ((page.Header.Flags & PageFlags.FirstPageOfStream) != 0) { stream = new Bitstream (page); streams.Add (page.Header.StreamSerialNumber, stream); active_streams.Add (stream); } if (stream == null) stream = streams [page.Header.StreamSerialNumber]; if (active_streams.Contains (stream) && stream.ReadPage (page)) active_streams.Remove (stream); if (pages != null) pages.Add (page); position += page.Size; } while (active_streams.Count > 0); end = position; return streams; }