public DescriptorBase(byte[] data, int offset)
        {
            _DescTag = (DescriptorTag)data[0 + offset];

            _Data = new byte[data[offset + 1]];
            Array.Copy(data, offset + 2, _Data, 0, _Data.Length);
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Descriptor"/> class.
 /// </summary>
 /// <param name="headerSize">Size of the descriptor header.</param>
 /// <param name="payloadSize">Size of the descriptor body.</param>
 /// <param name="tag">The descriptor tag.</param>
 public Descriptor(uint headerSize, uint payloadSize, DescriptorTag tag)
 {
     this.HeaderSize     = headerSize;
     this.PayloadSize    = payloadSize;
     this.Tag            = tag;
     this.SubDescriptors = new List <Descriptor>();
 }
Example #3
0
        /// <summary>
        /// Instantiiert einen Descriptor abhängig vom Inhalt.
        /// </summary>
        /// <param name="data">Descriptor-Daten</param>
        /// <param name="offset">Offset im Quellarray</param>
        /// <returns>Descriptor anhand des Inhalts</returns>
        public static DescriptorBase CreateDescriptor(byte[] data, int offset)
        {
            DescriptorTag tag = (DescriptorTag)data[offset];

            switch (tag)
            {
            case DescriptorTag.ConditionalAccess:
                return(new CaDescriptor(data, offset));

            // TODO: bei Bedarf weitere Descriptoren hier einfügen
            default:
                return(new DescriptorBase(data, offset));
            }
        }
Example #4
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="AppleElementaryStreamDescriptor" /> with a provided
        ///    header and handler by reading the contents from a
        ///    specified file.
        /// </summary>
        /// <param name="header">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    to use for the new instance.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLib.File" /> object to read the contents
        ///    of the box from.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object containing the
        ///    handler that applies to the new instance.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="CorruptFileException">
        ///    Valid data could not be read.
        /// </exception>
        public AppleElementaryStreamDescriptor(BoxHeader header,
                                               TagLib.File file,
                                               IsoHandlerBox handler)
            : base(header, file, handler)
        {
            /* ES_Descriptor Specifications
             *  Section 7.2.6.5 http://ecee.colorado.edu/~ecen5653/ecen5653/papers/ISO%2014496-1%202004.PDF
             */

            ByteVector box_data = file.ReadBlock(DataSize);

            decoder_config = new ByteVector();
            int offset = 0;

            // Elementary Stream Descriptor Tag
            if ((DescriptorTag)box_data[offset++] != DescriptorTag.ES_DescrTag)
            {
                throw new CorruptFileException("Invalid Elementary Stream Descriptor, missing tag.");
            }

            // We have a descriptor tag. Check that the remainder of the tag is at least [Base (3 bytes) + DecoderConfigDescriptor (15 bytes) + SLConfigDescriptor (3 bytes) + OtherDescriptors] bytes long
            uint es_length     = ReadLength(box_data, ref offset);
            uint min_es_length = 3 + 15 + 3; // Base minimum length

            if (es_length < min_es_length)
            {
                throw new CorruptFileException("Insufficient data present.");
            }

            es_id   = box_data.Mid(offset, 2).ToUShort();
            offset += 2;                                                                            // Done with ES_ID

            stream_dependence_flag = ((byte)((box_data[offset] >> 7) & 0x1) == 0x1 ? true : false); // 1st bit
            URL_flag        = ((byte)((box_data[offset] >> 6) & 0x1) == 0x1 ? true : false);        // 2nd bit
            ocr_stream_flag = ((byte)((box_data[offset] >> 5) & 0x1) == 0x1 ? true : false);        // 3rd bit
            stream_priority = (byte)(box_data[offset++] & 0x1F);                                    // Last 5 bits and we're done with this byte

            if (stream_dependence_flag)
            {
                min_es_length += 2; // We need 2 more bytes
                if (es_length < min_es_length)
                {
                    throw new CorruptFileException("Insufficient data present.");
                }

                dependsOn_ES_ID = box_data.Mid(offset, 2).ToUShort();
                offset         += 2; // Done with stream dependence
            }

            if (URL_flag)
            {
                min_es_length += 2; // We need 1 more byte
                if (es_length < min_es_length)
                {
                    throw new CorruptFileException("Insufficient data present.");
                }

                URLlength      = box_data[offset++]; // URL Length
                min_es_length += URLlength;          // We need URLength more bytes
                if (es_length < min_es_length)
                {
                    throw new CorruptFileException("Insufficient data present.");
                }

                URLstring = box_data.Mid(offset, URLlength).ToString(); // URL name
                offset   += URLlength;                                  // Done with URL name
            }

            if (ocr_stream_flag)
            {
                min_es_length += 2; // We need 2 more bytes
                if (es_length < min_es_length)
                {
                    throw new CorruptFileException("Insufficient data present.");
                }

                OCR_ES_Id = box_data.Mid(offset, 2).ToUShort();
                offset   += 2; // Done with OCR
            }

            while (offset < DataSize) // Loop through all trailing Descriptors Tags
            {
                DescriptorTag tag = (DescriptorTag)box_data[offset++];
                switch (tag)
                {
                case DescriptorTag.DecoderConfigDescrTag:     // DecoderConfigDescriptor
                {
                    // Check that the remainder of the tag is at least 13 bytes long (13 + DecoderSpecificInfo[] + profileLevelIndicationIndexDescriptor[])
                    if (ReadLength(box_data, ref offset) < 13)
                    {
                        throw new CorruptFileException("Could not read data. Too small.");
                    }

                    // Read a lot of good info.
                    object_type_id = box_data[offset++];

                    stream_type = (byte)(box_data[offset] >> 2);                                   // First 6 bits
                    upStream    = ((byte)((box_data[offset++] >> 1) & 0x1) == 0x1 ? true : false); // 7th bit and we're done with the stream bits

                    buffer_size_db = box_data.Mid(offset, 3).ToUInt();
                    offset        += 3; // Done with bufferSizeDB

                    max_bitrate = box_data.Mid(offset, 4).ToUInt();
                    offset     += 4; // Done with maxBitrate

                    average_bitrate = box_data.Mid(offset, 4).ToUInt();
                    offset         += 4; // Done with avgBitrate

                    // If there's a DecoderSpecificInfo[] array at the end it'll pick it up in the while loop
                }
                break;

                case DescriptorTag.DecSpecificInfoTag:     // DecoderSpecificInfo
                {
                    // The rest of the info is decoder specific.
                    uint length = ReadLength(box_data, ref offset);

                    decoder_config = box_data.Mid(offset, (int)length);
                    offset        += (int)length; // We're done with the config
                }
                break;


                case DescriptorTag.SLConfigDescrTag:     // SLConfigDescriptor
                {
                    // The rest of the info is SL specific.
                    uint length = ReadLength(box_data, ref offset);

                    offset += (int)length;     // Skip the rest of the descriptor as reported in the length so we can move onto the next one
                }
                break;

                case DescriptorTag.Forbidden_00:
                case DescriptorTag.Forbidden_FF:
                    throw new CorruptFileException("Invalid Descriptor tag.");

                default:
                {
                    /* TODO: Should we handle other optional descriptor tags?
                     *  ExtensionDescriptor extDescr[0 .. 255];
                     * LanguageDescriptor langDescr[0 .. 1];
                     * IPI_DescPointer ipiPtr[0 .. 1];
                     * IP_IdentificationDataSet ipIDS[0 .. 1];
                     * QoS_Descriptor qosDescr[0 .. 1];
                     */
                    uint length = ReadLength(box_data, ref offset); // Every descriptor starts with a length

                    offset += (int)length;                          // Skip the rest of the descriptor as reported in the length so we can move onto the next one
                    break;
                }
                }
            }
        }
 public DescriptorBase(DescriptorTag tag)
 {
     _DescTag = tag;
 }
Example #6
0
 public void ShowDescriptor(string title, DescriptorTag tags, string description, int cost = 0)
 {
     descriptor.Init(title, tags, description, cost);
     descriptorSwitcher.SwitchOn(descriptorTime);
 }