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 ((((byte) (page.Header.Flags & PageFlags.FirstPacketContinued)) == 0) && (this.previous_packet != null)) { if (this.ReadPacket(this.previous_packet)) { return true; } this.previous_packet = null; } ByteVector data = packets[i]; if (((i == 0) && (((byte) (page.Header.Flags & PageFlags.FirstPacketContinued)) != 0)) && (this.previous_packet != null)) { this.previous_packet.Add(data); data = this.previous_packet; } this.previous_packet = null; if (i == (packets.Length - 1)) { this.previous_packet = new ByteVector(data); } else if (this.ReadPacket(data)) { return true; } } return false; }
public Bitstream(Page page) { if (page == null) { throw new ArgumentNullException("page"); } this.codec = TagLib.Ogg.Codec.GetCodec(page.Packets[0]); this.first_absolute_granular_position = page.Header.AbsoluteGranularPosition; }
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; }
public void AddPage(Page page) { this.pages_read++; if (!this.first_page_header.HasValue) { this.first_page_header = new PageHeader?(page.Header); } if (page.Packets.Length != 0) { ByteVector[] packets = page.Packets; for (int i = 0; i < packets.Length; i++) { if (((((byte) (page.Header.Flags & PageFlags.FirstPacketContinued)) != 0) && (i == 0)) && (this.packets.Count > 0)) { this.packets[this.packets.Count - 1].Add(packets[0]); } else { this.packets.Add(packets[i]); } } } }
/// <summary> /// Reads the file until all streams have finished their /// property and tagging data. /// </summary> /// <param name="pages"> /// A <see cref="T:System.Collections.Generic.List`1"/> /// object to be filled with <see cref="Page" /> objects as /// they are read, or <see langword="null"/> if the pages /// are not to be stored. /// </param> /// <param name="end"> /// A <see cref="long" /> value reference to be updated to /// the postion of the first page not read by the current /// instance. /// </param> /// <returns> /// A <see cref="T:System.Collections.Generic.Dictionary`2" /// /> object containing stream serial numbers as the keys /// <see cref="Bitstream" /> objects as the values. /// </returns> 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; }
private Dictionary<uint, Bitstream> ReadStreams(List<Page> pages, out long end) { Dictionary<uint, Bitstream> dictionary = new Dictionary<uint, Bitstream>(); List<Bitstream> list = new List<Bitstream>(); long position = 0L; do { Bitstream bitstream = null; Page page = new Page(this, position); if (((byte) (page.Header.Flags & PageFlags.FirstPageOfStream)) != 0) { bitstream = new Bitstream(page); dictionary.Add(page.Header.StreamSerialNumber, bitstream); list.Add(bitstream); } if (bitstream == null) { bitstream = dictionary[page.Header.StreamSerialNumber]; } if (list.Contains(bitstream) && bitstream.ReadPage(page)) { list.Remove(bitstream); } if (pages != null) { pages.Add(page); } position += page.Size; } while (list.Count > 0); end = position; return dictionary; }