Beispiel #1
0
        /// <summary>
        /// Parses a <see cref="BlockType.SeekTable"/> <see cref="Media.Container.Node"/>
        /// </summary>
        /// <param name=nameof(node)>The <see cref="Media.Container.Node"/> to parse</param>
        internal protected List <Tuple <long, long, short> > ParseSeekTable(Media.Container.Node node)
        {
            VerifyBlockType(node, BlockType.SeekTable);
            ///	NOTE
            /// The number of seek points is implied by the metadata header 'length' field, i.e.equal to length / 18.
            List <Tuple <long, long, short> > seekPoints = new List <Tuple <long, long, short> >((int)(node == null ? 0 : node.DataSize / 18));

            if (node != null)
            {
                for (int i = 0, e = (int)node.DataSize; i < e; i += 18)
                {
                    //Add the decoded seekpoint
                    seekPoints.Add(new Tuple <long, long, short>(Common.Binary.Read64(node.Data, i, BitConverter.IsLittleEndian),
                                                                 Common.Binary.Read64(node.Data, i + 8, BitConverter.IsLittleEndian),
                                                                 Common.Binary.Read16(node.Data, i + 10, BitConverter.IsLittleEndian)));
                }
            }
            return(seekPoints);
        }
Beispiel #2
0
        /// <summary>
        /// Parses a <see cref="BlockType.VorbisComment"/> <see cref="Media.Container.Node"/>
        /// </summary>
        /// <param name=nameof(node)>The <see cref="Media.Container.Node"/> to parse</param>
        internal protected List <KeyValuePair <string, string> > ParseVorbisComment(Media.Container.Node node)
        {
            VerifyBlockType(node, BlockType.VorbisComment);

            List <KeyValuePair <string, string> > results = new List <KeyValuePair <string, string> >();

            int offset = 0;
            //https://www.xiph.org/vorbis/doc/v-comment.html
            //Read Vendor Length
            int vendorLength = Common.Binary.Read32(node.Data, offset, Media.Common.Binary.IsBigEndian);

            offset += 4;

            offset += vendorLength;

            //Determine if there is a comment list
            if (vendorLength > 0 && offset + 4 < node.DataSize)
            {
                //Read User Comment List
                int userCommentListLength = Common.Binary.Read32(node.Data, offset, Media.Common.Binary.IsBigEndian);

                //Move the offset
                offset += 4;

                //Read User Comment List if available
                if (userCommentListLength > 0)
                {
                    //While there is data to consume
                    while (offset + 4 < node.DataSize)
                    {
                        //Read the item length
                        int itemLength = Common.Binary.Read32(node.Data, offset, Media.Common.Binary.IsBigEndian);

                        //Move the offset
                        offset += 4;

                        //Invalid entry.
                        if (itemLength < 0 || itemLength + offset > node.DataSize)
                        {
                            continue;
                        }

                        //Get the string
                        string item = System.Text.Encoding.UTF8.GetString(node.Data, offset, itemLength);

                        //Split it
                        string[] parts = item.Split((char)Common.ASCII.EqualsSign);

                        //If there are 2 parts decide what to do.
                        if (parts.Length > 1)
                        {
                            //Add the key and value
                            results.Add(new KeyValuePair <string, string>(parts[0], parts[1]));

                            //Handle any parts needed such as title, date or timereference..
                            switch (parts[0].ToLowerInvariant())
                            {
                            //case "date": timereference "158760000"
                            //    {
                            //        //2016-04-12
                            //        break;
                            //    }
                            case "title":
                            {
                                m_Title = parts[1];
                                break;
                            }

                            default: break;
                            }
                        }
                        //else
                        //{
                        //    results.Add(new KeyValuePair<string, string>(parts[0], string.Empty));
                        //}

                        //Move the offset
                        offset += itemLength;
                    }
                }
            }

            return(results);
        }
Beispiel #3
0
 public static Node CreateNodeWithDataCopy(Node n)
 {
     return(new Node(n, false));
 }
Beispiel #4
0
 public static Node CreateNodeFrom(Node n)
 {
     return(new Node(n));
 }
Beispiel #5
0
 public static Node CreateNodeWithDataReference(Node n)
 {
     return(new Node(n, true));
 }
Beispiel #6
0
 public static bool DataReferenceEquals(Node a, Node b)
 {
     return(a == b || a != null && b != null && Object.ReferenceEquals(a.m_Data, b.m_Data));
 }
Beispiel #7
0
 public static bool DataEquals(Node a, Node b)
 {
     return(a == b || a != null && b != null && a.DataAssigned && a.m_Data.SequenceEqual(b.m_Data));
 }
Beispiel #8
0
 public static bool IsCompleteEquals(Node a, Node b)
 {
     return(a == b || a != null && b != null && a.IsComplete == b.IsComplete);
 }
Beispiel #9
0
 public static bool MasterEquals(Node a, Node b)
 {
     return(a == b || a != null && b != null && a.Master == b.Master);
 }
Beispiel #10
0
 public static bool IdentifierSizeEquals(Node a, Node b)
 {
     return(a == b || a != null && b != null && a.IdentifierSize == b.IdentifierSize);
 }
Beispiel #11
0
 public static bool DataSizeEquals(Node a, Node b)
 {
     return(a == b || a != null && b != null && a.DataSize == b.DataSize);
 }
Beispiel #12
0
 public static bool TotalSizeEquals(Node a, Node b)
 {
     return(a == b || a != null && b != null && a.TotalSize == b.TotalSize);
 }