public PageHeader(File file, long position)
{
if (file == null)
throw new ArgumentNullException ("file");
if (position < 0 || position > file.Length - 27)
throw new ArgumentOutOfRangeException (
"position");
file.Seek (position);
// An Ogg page header is at least 27 bytes, so we'll go
// ahead and read that much and then get the rest when
// we're ready for it.
ByteVector data = file.ReadBlock (27);
if (data.Count < 27 || !data.StartsWith ("OggS"))
System.Console.WriteLine(
"Error reading page header");
version = data [4];
this.flags = (PageFlags) data [5];
absolute_granular_position = data.Mid(6, 8).ToULong (
false);
stream_serial_number = data.Mid(14, 4).ToUInt (false);
page_sequence_number = data.Mid(18, 4).ToUInt (false);
// Byte number 27 is the number of page segments, which
// is the only variable length portion of the page
// header. After reading the number of page segments
// we'll then read in the coresponding data for this
// count.
int page_segment_count = data [26];
ByteVector page_segments =
file.ReadBlock (page_segment_count);
// Another sanity check.
if (page_segment_count < 1 ||
page_segments.Count != page_segment_count)
System.Console.WriteLine(
"Incorrect number of page segments");
// The base size of an Ogg page 27 bytes plus the number
// of lacing values.
size = (uint)(27 + page_segment_count);
packet_sizes = new List<int> ();
int packet_size = 0;
data_size = 0;
for (int i = 0; i < page_segment_count; i++) {
data_size += page_segments [i];
packet_size += page_segments [i];
if (page_segments [i] < 255) {
packet_sizes.Add (packet_size);
packet_size = 0;
}
}
if (packet_size > 0)
packet_sizes.Add (packet_size);
}