Пример #1
0
 public override string ToTextualConvention(Container.Node node)
 {
     if (node.Master.Equals(this))
     {
         return(PacketizedElementaryStreamReader.ToTextualConvention(node.Identifier));
     }
     return(base.ToTextualConvention(node));
 }
Пример #2
0
 //Might need the data not the identifier
 public static string ToTextualConvention(byte[] identifier)
 {
     return(PacketizedElementaryStreamReader.ToTextualConvention(identifier));
 }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override Container.Node ReadNext()
        {
            //Read a code
            byte[] identifier = PacketizedElementaryStreamReader.ReadIdentifier(this);

            //Check for sync
            if (Common.Binary.ReadU24(identifier, 0, Media.Common.Binary.IsBigEndian) != Common.Binary.ReadU24(Mpeg.StartCodes.StartCodePrefix, 0, Media.Common.Binary.IsBigEndian))
            {
                throw new InvalidOperationException("Cannot Find StartCode Prefix.");
            }

            int length = 0, lengthSize = PacketizedElementaryStreamReader.LengthSize;

            //Determine which type of node we are dealing with
            switch (identifier[3])
            {
            case Mpeg.StreamTypes.PackHeader:
            {
                //No bytes are related to the length yet
                lengthSize = 0;

                //MPEG 1 Used only 2 bits 0 1
                //MPEG 2 Used 4 bits 0 0 0 1
                byte next = (byte)ReadByte();

                //We are at the 5th byte. (IdentifierSize + 1)
                int offset = 5;

                //Determine which version of the Pack Header this is
                switch (next >> 6)
                {
                case 0:             //MPEG 1
                {
                    //Read 7 more bytes (The rest of the MPEG 1 Pack Header)
                    Array.Resize(ref identifier, 12);
                    Read(identifier, offset, 7);

                    break;
                }

                default:             //MPEG 2
                {
                    //Read 9 more bytes (the rest of the MPEG 2 Pack Header)
                    Array.Resize(ref identifier, 14);
                    Read(identifier, offset, 9);

                    //Include Stuffing length with mask (00000111) reversed bits
                    length = (byte)(identifier[13] & 0x07);

                    break;
                }
                }

                //Put the 4th byte back
                identifier[IdentifierSize] = next;

                break;
            }

            case Mpeg.StreamTypes.ProgramEnd:
            {
                //End of Program Stream.
                break;
            }

            default:     //PESPacket
            {
                //lengthSize already set
                length = PacketizedElementaryStreamReader.DecodeLength(PacketizedElementaryStreamReader.ReadLength(this));
                break;
            }
            }

            return(new Media.Container.Node(this, identifier, lengthSize, Position, length, length <= Remaining));
        }