private void Read(ReadStyle properties_style) { long end; Dictionary <uint, Bitstream> streams = ReadStreams(null, out end); List <ICodec> codecs = new List <ICodec> (); InvariantStartPosition = end; InvariantEndPosition = Length; foreach (uint id in streams.Keys) { tag.AddComment(id, streams [id].Codec.CommentData); codecs.Add(streams [id].Codec); } if (properties_style == ReadStyle.None) { return; } PageHeader last_header = LastPageHeader; TimeSpan duration = streams [last_header.StreamSerialNumber].GetDuration(last_header.AbsoluteGranularPosition); properties = new Properties(duration, codecs); }
public bool Equals(PageHeader other) { return(_packet_sizes == other._packet_sizes && _version == other._version && _flags == other._flags && _absolute_granular_position == other._absolute_granular_position && _stream_serial_number == other._stream_serial_number && _page_sequence_number == other._page_sequence_number && _size == other._size && _data_size == other._data_size); }
public static void OverwriteSequenceNumbers(File file, long position, IDictionary <uint, int> shiftTable) { bool done = true; foreach (KeyValuePair <uint, int> pair in shiftTable) { if (pair.Value != 0) { done = false; break; } } if (done) { return; } while (position < file.Length) { PageHeader header = new PageHeader(file, position); int size = (int)(header.Size + header.DataSize); if (shiftTable.ContainsKey(header.StreamSerialNumber) && shiftTable [header.StreamSerialNumber] != 0) { file.Seek(position); ByteVector page_data = file.ReadBlock(size); ByteVector new_data = ByteVector.FromUInt( (uint)(header.PageSequenceNumber + shiftTable [header.StreamSerialNumber]), false); for (int i = 18; i < 22; i++) { page_data [i] = new_data [i - 18]; } for (int i = 22; i < 26; i++) { page_data [i] = 0; } new_data.Add(ByteVector.FromUInt( page_data.Checksum, false)); file.Seek(position + 18); file.WriteBlock(new_data); } position += size; } }
public Page (ByteVectorCollection packets, PageHeader header) : this (header) { if (packets == null) throw new ArgumentNullException ("packets"); this.packets = packets; List<int> packet_sizes = new List<int> (); // Build a page from the list of packets. foreach (ByteVector v in packets) packet_sizes.Add (v.Count); header.PacketSizes = packet_sizes.ToArray (); }
public PageHeader(PageHeader original, uint offset, PageFlags flags) { _version = original._version; _flags = flags; _absolute_granular_position = original._absolute_granular_position; _stream_serial_number = original._stream_serial_number; _page_sequence_number = original._page_sequence_number + offset; _size = original._size; _data_size = original._data_size; _packet_sizes = new List <int> (); if (_page_sequence_number == 0 && (flags & PageFlags.FirstPacketContinued) == 0) { _flags |= PageFlags.FirstPageOfStream; } }
public Page(ByteVectorCollection packets, PageHeader header) : this(header) { if (packets == null) { throw new ArgumentNullException("packets"); } this.packets = packets; List <int> packet_sizes = new List <int> (); // Build a page from the list of packets. foreach (ByteVector v in packets) { packet_sizes.Add(v.Count); } header.PacketSizes = packet_sizes.ToArray(); }
public bool Equals (PageHeader other) { return _packet_sizes == other._packet_sizes && _version == other._version && _flags == other._flags && _absolute_granular_position == other._absolute_granular_position && _stream_serial_number == other._stream_serial_number && _page_sequence_number == other._page_sequence_number && _size == other._size && _data_size == other._data_size; }
public PageHeader (PageHeader original, uint offset, PageFlags flags) { _version = original._version; _flags = flags; _absolute_granular_position = original._absolute_granular_position; _stream_serial_number = original._stream_serial_number; _page_sequence_number = original._page_sequence_number + offset; _size = original._size; _data_size = original._data_size; _packet_sizes = new List<int> (); if (_page_sequence_number == 0 && (flags & PageFlags.FirstPacketContinued) == 0) _flags |= PageFlags.FirstPageOfStream; }
protected Page(PageHeader header) { this.header = header; packets = new ByteVectorCollection(); }
public static void OverwriteSequenceNumbers (File file, long position, IDictionary<uint, int> shiftTable) { bool done = true; foreach (KeyValuePair<uint, int> pair in shiftTable) if (pair.Value != 0) { done = false; break; } if (done) return; while (position < file.Length) { PageHeader header = new PageHeader (file, position); int size = (int) (header.Size + header.DataSize); if (shiftTable.ContainsKey (header.StreamSerialNumber) && shiftTable [header.StreamSerialNumber] != 0) { file.Seek (position); ByteVector page_data = file.ReadBlock (size); ByteVector new_data = ByteVector.FromUInt ( (uint)(header.PageSequenceNumber + shiftTable [header.StreamSerialNumber]), false); for (int i = 18; i < 22; i ++) page_data [i] = new_data [i - 18]; for (int i = 22; i < 26; i++) page_data [i] = 0; new_data.Add (ByteVector.FromUInt ( page_data.Checksum, false)); file.Seek (position + 18); file.WriteBlock (new_data); } position += size; } }
protected Page (PageHeader header) { this.header = header; packets = new ByteVectorCollection (); }
public Page [] Paginate(out int change) { // Ogg Pagination: Welcome to sucksville! // If you don't understand this, you're not alone. // It is confusing as Hell. // TODO: Document this method, in the mean time, there // is always http://xiph.org/ogg/doc/framing.html if (pages_read == 0) { change = 0; return(new Page [0]); } int count = pages_read; ByteVectorCollection packets = new ByteVectorCollection( this.packets); PageHeader first_header = (PageHeader)first_page_header; List <Page> pages = new List <Page> (); uint index = 0; bool bos = first_header.PageSequenceNumber == 0; if (bos) { pages.Add(new Page(new ByteVectorCollection(packets [0]), first_header)); index++; packets.RemoveAt(0); count--; } int lacing_per_page = 0xfc; if (count > 0) { int total_lacing_bytes = 0; for (int i = 0; i < packets.Count; i++) { total_lacing_bytes += GetLacingValueLength( packets, i); } lacing_per_page = Math.Min(total_lacing_bytes / count + 1, lacing_per_page); } int lacing_bytes_used = 0; ByteVectorCollection page_packets = new ByteVectorCollection(); bool first_packet_continued = false; while (packets.Count > 0) { int packet_bytes = GetLacingValueLength(packets, 0); int remaining = lacing_per_page - lacing_bytes_used; bool whole_packet = packet_bytes <= remaining; if (whole_packet) { page_packets.Add(packets [0]); lacing_bytes_used += packet_bytes; packets.RemoveAt(0); } else { page_packets.Add(packets [0].Mid(0, remaining * 0xff)); packets [0] = packets [0].Mid(remaining * 0xff); lacing_bytes_used += remaining; } if (lacing_bytes_used == lacing_per_page) { pages.Add(new Page(page_packets, new PageHeader(first_header, index, first_packet_continued ? PageFlags.FirstPacketContinued : PageFlags.None))); page_packets = new ByteVectorCollection(); lacing_bytes_used = 0; index++; count--; first_packet_continued = !whole_packet; } } if (page_packets.Count > 0) { pages.Add(new Page(page_packets, new PageHeader( first_header.StreamSerialNumber, index, first_packet_continued ? PageFlags.FirstPacketContinued : PageFlags.None))); index++; count--; } change = -count; return(pages.ToArray()); }