示例#1
0
        /// <summary>
        ///    Repaginates the pages passed into the current instance to
        ///    handle changes made to the Xiph comment.
        /// </summary>
        /// <param name="change">
        ///    A <see cref="int" /> value reference containing the
        ///    the difference between the number of pages returned and
        ///    the number of pages that were added to the class.
        /// </param>
        /// <returns>
        ///    A <see cref="Page[]" /> containing the new page
        ///    collection.
        /// </returns>
        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();
        }
示例#2
0
        public Page[] Paginate(out int change)
        {
            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());
        }
示例#3
0
        /// <summary>
        ///    Repaginates the pages passed into the current instance to
        ///    handle changes made to the Xiph comment.
        /// </summary>
        /// <param name="change">
        ///    A <see cref="int" /> value reference containing the
        ///    the difference between the number of pages returned and
        ///    the number of pages that were added to the class.
        /// </param>
        /// <returns>
        ///    A <see cref="T:Page[]" /> containing the new page
        ///    collection.
        /// </returns>
        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());
        }
 public Page[] Paginate(out int change)
 {
     if (this.pages_read == 0)
     {
         change = 0;
         return new Page[0];
     }
     int num = this.pages_read;
     ByteVectorCollection packets = new ByteVectorCollection(this.packets);
     PageHeader header = this.first_page_header.Value;
     List<Page> list = new List<Page>();
     uint offset = 0;
     if (header.PageSequenceNumber == 0)
     {
         ByteVector[] vectorArray1 = new ByteVector[] { packets[0] };
         list.Add(new Page(new ByteVectorCollection(vectorArray1), header));
         offset++;
         packets.RemoveAt(0);
         num--;
     }
     int num3 = 0xfc;
     if (num > 0)
     {
         int num4 = 0;
         for (int i = 0; i < packets.Count; i++)
         {
             num4 += GetLacingValueLength(packets, i);
         }
         num3 = Math.Min((num4 / num) + 1, num3);
     }
     int num6 = 0;
     ByteVectorCollection vectors2 = new ByteVectorCollection();
     bool flag2 = false;
     while (packets.Count > 0)
     {
         int lacingValueLength = GetLacingValueLength(packets, 0);
         int num8 = num3 - num6;
         bool flag3 = lacingValueLength <= num8;
         if (flag3)
         {
             vectors2.Add(packets[0]);
             num6 += lacingValueLength;
             packets.RemoveAt(0);
         }
         else
         {
             vectors2.Add(packets[0].Mid(0, num8 * 0xff));
             packets[0] = packets[0].Mid(num8 * 0xff);
             num6 += num8;
         }
         if (num6 == num3)
         {
             list.Add(new Page(vectors2, new PageHeader(header, offset, !flag2 ? PageFlags.None : PageFlags.FirstPacketContinued)));
             vectors2 = new ByteVectorCollection();
             num6 = 0;
             offset++;
             num--;
             flag2 = !flag3;
         }
     }
     if (vectors2.Count > 0)
     {
         list.Add(new Page(vectors2, new PageHeader(header.StreamSerialNumber, offset, !flag2 ? PageFlags.None : PageFlags.FirstPacketContinued)));
         offset++;
         num--;
     }
     change = -num;
     return list.ToArray();
 }