コード例 #1
0
        public void Parse(ByteVector data)
        {
            if (data != null)
            {
                // 11 buffer is the minimum size for an APE item
                if (data.Count < 11)
                {
                    TagLibDebugger.Debug("APE.Item.Parse() -- no data in item");
                    return;
                }

                uint value_length = data.Mid(0, 4).ToUInt(false);
                uint flags        = data.Mid(4, 4).ToUInt(false);

                int pos = data.Find(new ByteVector(1), 8);

                key   = data.Mid(8, pos - 8).ToString(StringType.UTF8);
                value = data.Mid(pos + 1, (int)value_length);

                ReadOnly = (flags & 1) == 1;
                Type     = (ApeItemType)((flags >> 1) & 3);

                if (Type != ApeItemType.Binary)
                {
                    text.Clear();
                    text = new StringCollection(ByteVectorCollection.Split(value, (byte)0), StringType.UTF8);
                }
            }
            else
            {
                throw new ArgumentNullException("data");
            }
        }
コード例 #2
0
 protected OggPage(ByteVectorCollection packets, uint stream_serial_number,
                   int page_number, bool first_packet_continued,
                   bool last_packet_completed)
     : this(packets, stream_serial_number, page_number,
            first_packet_continued, last_packet_completed, false)
 {
 }
コード例 #3
0
        public static OggPage[] Paginate(ByteVectorCollection packets, PaginationStrategy strategy, uint streamSerialNumber,
                                         int firstPage, bool firstPacketContinued, bool lastPacketCompleted, bool containsLastPacket)
        {
            ArrayList l = new ArrayList();

            int totalSize = 0;

            foreach (ByteVector b in packets)
            {
                totalSize += b.Count;
            }

            if (strategy == PaginationStrategy.Repaginate || totalSize + packets.Count > 255 * 256)
            {
                TagLibDebugger.Debug("Ogg.Page.Paginate() -- Sorry!  Repagination is not yet implemented.");
                return((OggPage[])l.ToArray(typeof(OggPage)));
            }

            // TODO: Handle creation of multiple pages here with appropriate pagination.

            OggPage p = new OggPage(packets, streamSerialNumber, firstPage, firstPacketContinued,
                                    lastPacketCompleted, containsLastPacket);

            l.Add(p);

            return((OggPage[])l.ToArray(typeof(OggPage)));
        }
コード例 #4
0
        public static ByteVectorCollection Split(ByteVector vector, ByteVector pattern, int alignment, int maximum)
        {
            if (vector != null)
            {
                if (pattern != null)
                {
                    ByteVectorCollection list = new ByteVectorCollection();
                    int previousOffset        = 0;
                    for (int offset = vector.Find(pattern, 0, alignment);
                         offset != -1 && (maximum == 0 || maximum > list.Count + 1);
                         offset = vector.Find(pattern, offset + pattern.Count, alignment))
                    {
                        list.Add(vector.Mid(previousOffset, offset - previousOffset));
                        previousOffset = offset + pattern.Count;
                    }

                    if (previousOffset < vector.Count)
                    {
                        list.Add(vector.Mid(previousOffset, vector.Count - previousOffset));
                    }

                    return(list);
                }
                else
                {
                    throw new ArgumentNullException("pattern");
                }
            }
            else
            {
                throw new ArgumentNullException("vector");
            }
        }
コード例 #5
0
        //public Mpeg4AppleDataBox[] DataBoxes(ByteVectorCollection list)
        public IList <Mpeg4AppleDataBox> DataBoxes(ByteVectorCollection list)
        {
            //ArrayList l = new ArrayList();
            List <Mpeg4AppleDataBox> boxes = new List <Mpeg4AppleDataBox>();

            // Check each box to see if the match any of the provided types.
            // If a match is found, loop through the children and add any data box.
            foreach (Mpeg4Box box in listBox.Children)
            {
                foreach (ByteVector vector in list)
                {
                    if (FixId(vector) == box.BoxType)
                    {
                        foreach (Mpeg4Box dataBox in box.Children)
                        {
                            //if (dataBox.GetType() == typeof(Mpeg4AppleDataBox))
                            Mpeg4AppleDataBox appleDataBox = dataBox as Mpeg4AppleDataBox;
                            if (appleDataBox != null)
                            {
                                boxes.Add(appleDataBox);
                            }
                        }
                    }
                }
            }

            // Return the results as an numbers.
            return(boxes);
            //(Mpeg4AppleDataBox[])l.ToArray(typeof(Mpeg4AppleDataBox));
        }
コード例 #6
0
        protected OggPage(ByteVectorCollection packets, uint stream_serial_number,
                          int page_number, bool first_packet_continued,
                          bool last_packet_completed, bool contains_last_packet)
        {
            //file = null;
            fileOffset = -1;
            //packetOffset = 0;
            //dataSize = 0;
            header           = new OggPageHeader();
            firstPacketIndex = -1;
            this.packets     = packets;

            ByteVector data         = new ByteVector();
            ArrayList  packet_sizes = new ArrayList();

            header.FirstPageOfStream    = (page_number == 0 && !first_packet_continued);
            header.LastPageOfStream     = contains_last_packet;
            header.FirstPacketContinued = first_packet_continued;
            header.LastPacketCompleted  = last_packet_completed;
            header.StreamSerialNumber   = stream_serial_number;
            header.PageSequenceNumber   = page_number;

            // Build a page from the text of packets.
            foreach (ByteVector v in packets)
            {
                packet_sizes.Add(v.Count);
                data.Add(v);
            }

            header.SetPacketSizes((int[])packet_sizes.ToArray(typeof(int)));
        }
コード例 #7
0
 public StringCollection(ByteVectorCollection text, StringType type)
 {
     foreach (ByteVector vector in text)
     {
         Add(vector.ToString(type));
     }
 }
コード例 #8
0
        private void ParseUniqueFields(ByteVector data)
        {
            ByteVectorCollection fields = ByteVectorCollection.Split(data, (byte)0);

            if (fields.Count != 2)
            {
                return;
            }

            owner      = fields[0].ToString(StringType.Latin1);
            identifier = fields[1];
        }
コード例 #9
0
ファイル: OggFile.cs プロジェクト: windygu/alexandrialibrary
 protected void ClearPageData()
 {
     streamSerialNumber = 0;
     pages             = new List <OggPage>(); //new ArrayList ();
     firstPageHeader   = null;
     lastPageHeader    = null;
     packetToPageMap   = new List <IntCollection>();          //new ArrayList();
     dirtyPackets      = new Dictionary <uint, ByteVector>(); //new Hashtable ();
     dirtyPages        = new IntCollection();
     currentPage       = null;
     currentPacketPage = null;
     currentPackets    = null;
 }
コード例 #10
0
        //////////////////////////////////////////////////////////////////////////
        // public methods
        //////////////////////////////////////////////////////////////////////////
        public OggPage(OggFile file, long pageOffset)
        {
            this.file       = file;
            this.fileOffset = pageOffset;
            //packetOffset = 0;
            //dataSize = 0;
            header           = new OggPageHeader(file, pageOffset);
            firstPacketIndex = -1;
            packets          = new ByteVectorCollection();

            if (file != null)
            {
                packetOffset = fileOffset + header.Size;
                dataSize     = header.DataSize;
            }
        }
コード例 #11
0
        private void ParsePrivateFields(ByteVector data)
        {
            if (data.Count < 1)
            {
                TagLibDebugger.Debug("A private frame must contain at least 1 byte.");
                return;
            }

            ByteVectorCollection list = ByteVectorCollection.Split(data, TextDelimiter(StringType.Latin1), 1, 2);

            if (list.Count == 2)
            {
                owner = list[0].ToString(StringType.Latin1);
                data  = list[1];
            }
        }
コード例 #12
0
        // Set the data with the given box type, strings, and flags.
        public void SetText(ByteVector type, string[] text)
        {
            // Remove empty data and return.
            if (text == null)
            {
                listBox.RemoveChildren(FixId(type));
                return;
            }

            // Create a text...
            ByteVectorCollection data = new ByteVectorCollection();

            // and populate it with the ByteVectorized strings.
            foreach (string value in text)
            {
                data.Add(ByteVector.FromString(value, StringType.UTF8));
            }

            // Send our final byte vectors to SetData
            SetData(type, data, (uint)Mpeg4ContentType.ContainsText);
        }
コード例 #13
0
        private void ParseTextIdentifierFields(ByteVector data)
        {
            // read the string data type (the first byte of the field data)

            textEncoding = (StringType)data[0];

            // split the byte numbers into chunks based on the string type (two byte delimiter
            // for unicode encodings)

            int byteAlign = textEncoding == StringType.Latin1 || textEncoding == StringType.UTF8 ? 1 : 2;

            ByteVectorCollection list = ByteVectorCollection.Split(data.Mid(1), TextDelimiter(textEncoding), byteAlign);

            fieldList.Clear();

            // append those split values to the text and make sure that the new string'field
            // type is the same specified for this frame

            foreach (ByteVector vector in list)
            {
                fieldList.Add(vector.ToString(textEncoding));
            }
        }
コード例 #14
0
        public void SetData(ByteVector type, ByteVectorCollection data, uint flags)
        {
            if (data != null)
            {
                if (data.Count > 0)
                {
                    Mpeg4AppleDataBox[] boxes = new Mpeg4AppleDataBox[data.Count];
                    for (int i = 0; i < data.Count; i++)
                    {
                        boxes[i] = new Mpeg4AppleDataBox(data[i], flags);
                    }

                    SetData(type, boxes);
                }
                else
                {
                    ClearData(type);
                }
            }
            else
            {
                ClearData(type);
            }
        }
コード例 #15
0
        private void ParseCommentsFields(ByteVector data)
        {
            if (data.Count < 5)
            {
                TagLibDebugger.Debug("A comment frame must contain at least 5 bytes.");
                return;
            }

            textEncoding = (StringType)data[0];
            language     = data.Mid(1, 3);

            int byte_align = textEncoding == StringType.Latin1 || textEncoding == StringType.UTF8 ? 1 : 2;

            ByteVectorCollection l = ByteVectorCollection.Split(data.Mid(4), TextDelimiter(textEncoding), byte_align, 2);

            if (l.Count == 2)
            {
                if (l[0].Data != null && l[0].Data.Count > 0)
                {
                    description = l[0].ToString(textEncoding);
                }
                else
                {
                    description = string.Empty;
                }

                if (l[1].Data != null && l[1].Data.Count > 0)
                {
                    text = l[1].ToString(textEncoding);
                }
                else
                {
                    text = string.Empty;
                }
            }
        }
コード例 #16
0
 public static OggPage[] Paginate(ByteVectorCollection packets, PaginationStrategy strategy, uint streamSerialNumber,
                                  int firstPage)
 {
     return(Paginate(packets, strategy, streamSerialNumber, firstPage, false));
 }
コード例 #17
0
ファイル: OggFile.cs プロジェクト: windygu/alexandrialibrary
        public ByteVector GetPacket(uint index)
        {
            // Check to see if we're called setPacket() for this packet since the last
            // save:

            if (dirtyPackets.ContainsKey(index))
            {
                return(dirtyPackets[index]);
            }

            // If we haven'type indexed the page where the packet we're interested in starts,
            // begin reading pages until we have.

            while (packetToPageMap.Count <= index)
            {
                if (!NextPage())
                {
                    TagLibDebugger.Debug("Ogg.File.Packet() -- Could not find the requested packet.");
                    return(null);
                }
            }

            // Start reading at the first page that contains part (or all) of this packet.
            // If the last read stopped at the packet that we're interested in, don'type
            // reread its packet text.  (This should make sequential packet reads fast.)

            int pageIndex = ((IntCollection)packetToPageMap[(int)index])[0];

            if (currentPacketPage != pages[pageIndex])
            {
                currentPacketPage = pages[pageIndex];
                currentPackets    = currentPacketPage.Packets;
            }

            // If the packet is completely contained in the first page that it'field in, then
            // just return it now.

            if ((currentPacketPage.ContainsPacket((int)index) & ContainsPacketSettings.CompletePacket) != 0)
            {
                return(currentPackets[(int)(index - currentPacketPage.FirstPacketIndex)]);
            }

            // If the packet is *not* completely contained in the first page that it'field a
            // part of then that packet trails off the end of the page.  Continue appending
            // the pages' packet data until we hit a page that either does not end with the
            // packet that we're fetching or where the last packet is complete.

            ByteVector packet = currentPackets[currentPackets.Count - 1];

            while ((currentPacketPage.ContainsPacket((int)index) & ContainsPacketSettings.EndsWithPacket) != 0 &&
                   !currentPacketPage.Header.LastPacketCompleted)
            {
                pageIndex++;
                if (pageIndex == pages.Count && !NextPage())
                {
                    TagLibDebugger.Debug("Ogg.File.Packet() -- Could not find the requested packet.");
                    return(null);
                }

                currentPacketPage = (OggPage)pages[pageIndex];
                currentPackets    = currentPacketPage.Packets;
                packet.Add(currentPackets[0]);
            }

            return(packet);
        }
コード例 #18
0
ファイル: OggFile.cs プロジェクト: windygu/alexandrialibrary
        private void WritePageGroup(IntCollection page_group)
        {
            if (page_group.IsEmpty)
            {
                return;
            }

            ByteVectorCollection packets = new ByteVectorCollection();

            // If the first page of the group isn'type dirty, append its partial content here.

            if (!dirtyPages.Contains(((OggPage)this.pages[page_group[0]]).FirstPacketIndex))
            {
                packets.Add(((OggPage)this.pages[page_group[0]]).Packets[0]);
            }

            int previous_packet = -1;
            int original_size   = 0;

            for (int i = 0; i < page_group.Count; i++)
            {
                int page = page_group[i];

                uint first_packet = (uint)((OggPage)this.pages[page]).FirstPacketIndex;
                uint last_packet  = first_packet + ((OggPage)this.pages[page]).PacketCount - 1;

                for (uint j = first_packet; j <= last_packet; j++)
                {
                    if (i == page_group.Count - 1 && j == last_packet && !dirtyPages.Contains((int)j))
                    {
                        packets.Add(((OggPage)this.pages[page]).Packets[((OggPage)this.pages[page]).Packets.Count - 1]);
                    }
                    else if ((int)j != previous_packet)
                    {
                        previous_packet = (int)j;
                        packets.Add(GetPacket(j));
                    }
                }
                original_size += ((OggPage)this.pages[page]).Size;
            }

            bool continued = ((OggPage)this.pages[page_group[0]]).Header.FirstPacketContinued;
            bool completed = ((OggPage)this.pages[page_group[page_group.Count - 1]]).Header.LastPacketCompleted;

            // TODO: This pagination method isn'type accurate for what'field being done here.
            // This should account for real possibilities like non-aligned packets and such.

            OggPage[] pages = OggPage.Paginate(packets, PaginationStrategy.SinglePagePerGroup,
                                               streamSerialNumber, page_group[0],
                                               continued, completed);

            ByteVector data = new ByteVector();

            foreach (OggPage p in pages)
            {
                data.Add(p.Render());
            }

            // The insertion algorithms could also be improve to queue and prioritize data
            // on the way out.  Currently it requires rewriting the file for every page
            // group rather than just once; however, for tagging applications there will
            // generally only be one page group, so it'field not worth the time for the
            // optimization at the moment.

            Insert(data, ((OggPage)this.pages[page_group[0]]).FileOffset, original_size);

            // Update the page index to include the pages we just created and to delete the
            // old pages.

            foreach (OggPage p in pages)
            {
                int index = p.Header.PageSequenceNumber;
                this.pages[index] = p;
            }
        }
コード例 #19
0
 public static OggPage[] Paginate(ByteVectorCollection packets, PaginationStrategy strategy, uint streamSerialNumber,
                                  int firstPage, bool firstPacketContinued)
 {
     return(Paginate(packets, strategy, streamSerialNumber, firstPage,
                     firstPacketContinued, true));
 }
コード例 #20
0
 protected OggPage(ByteVectorCollection packets, uint stream_serial_number,
                   int page_number)
     : this(packets, stream_serial_number, page_number, false)
 {
 }
コード例 #21
0
 public StringCollection(ByteVectorCollection text) : this(text, StringType.UTF8)
 {
 }