Ejemplo n.º 1
0
 public static Mp4Descriptor CreateDescriptor(Mp4DataStream bitstream)
 {
     int tag = (int)bitstream.ReadBytes(1);
     int bytesRead = 1;
     int size = 0;
     int b = 0;
     do
     {
         b = (int)bitstream.ReadBytes(1);
         size <<= 7;
         size |= b & 0x7f;
         bytesRead++;
     } while ((b & 0x80) == 0x80);
     Mp4Descriptor descriptor = new Mp4Descriptor(tag, size);
     switch (tag)
     {
         case MP4ES_DescriptorTag:
             descriptor.CreateESDescriptor(bitstream);
             break;
         case MP4DecoderConfigDescriptorTag:
             descriptor.CreateDecoderConfigDescriptor(bitstream);
             break;
         case MP4DecSpecificInfoDescriptorTag:
             descriptor.CreateDecSpecificInfoDescriptor(bitstream);
             break;
         default:
             break;
     }
     bitstream.SkipBytes(descriptor._size - descriptor._bytesRead);
     descriptor._bytesRead = bytesRead + descriptor._size;
     return descriptor;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Loads M4ESDAtom atom from the input bitstream.
 /// </summary>
 /// <param name="bitstream">The input bitstream.</param>
 /// <returns>The number of bytes loaded.</returns>
 public long create_esd_atom(Mp4DataStream bitstream)
 {
     create_full_atom(bitstream);
     esd_descriptor = Mp4Descriptor.CreateDescriptor(bitstream);
     _bytesRead    += esd_descriptor.BytesRead;
     return(_bytesRead);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the MP4ES_Descriptor from the input bitstream.
        /// </summary>
        /// <param name="bitstream">The input bitstream.</param>
        public void CreateESDescriptor(Mp4DataStream bitstream)
        {
            int  ES_ID = (int)bitstream.ReadBytes(2);
            int  flags = (int)bitstream.ReadBytes(1);
            bool streamDependenceFlag = (flags & (1 << 7)) != 0;
            bool urlFlag = (flags & (1 << 6)) != 0;
            bool ocrFlag = (flags & (1 << 5)) != 0;

            _bytesRead += 3;
            if (streamDependenceFlag)
            {
                bitstream.SkipBytes(2);
                _bytesRead += 2;
            }
            if (urlFlag)
            {
                int str_size = (int)bitstream.ReadBytes(1);
                bitstream.ReadString(str_size);
                _bytesRead += str_size + 1;
            }
            if (ocrFlag)
            {
                bitstream.SkipBytes(2);
                _bytesRead += 2;
            }
            while (_bytesRead < _size)
            {
                Mp4Descriptor descriptor = CreateDescriptor(bitstream);
                _children.Add(descriptor);
                _bytesRead += descriptor.BytesRead;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Looks up a child descriptor with the specified <code>type</code>, skips the <code>number</code> children with the same type before retrieving.
        /// </summary>
        /// <param name="type">The type of the descriptor.</param>
        /// <param name="number">The number of child descriptors to skip.</param>
        /// <returns>The descriptor if found, otherwise null.</returns>
        public Mp4Descriptor Lookup(int type, int number)
        {
            int position = 0;

            for (int i = 0; i < _children.Count; i++)
            {
                Mp4Descriptor descriptor = _children[i];
                if (descriptor.Type == type)
                {
                    if (position >= number)
                    {
                        return(descriptor);
                    }
                    position++;
                }
            }
            return(null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads the MP4DecoderConfigDescriptor from the input bitstream.
        /// </summary>
        /// <param name="bitstream">The input bitstream.</param>
        public void CreateDecoderConfigDescriptor(Mp4DataStream bitstream)
        {
            int  objectTypeIndication = (int)bitstream.ReadBytes(1);
            int  value      = (int)bitstream.ReadBytes(1);
            bool upstream   = (value & (1 << 1)) > 0;
            byte streamType = (byte)(value >> 2);

            value = (int)bitstream.ReadBytes(2);
            int bufferSizeDB = value << 8;

            value         = (int)bitstream.ReadBytes(1);
            bufferSizeDB |= value & 0xff;
            int maxBitRate = (int)bitstream.ReadBytes(4);
            int minBitRate = (int)bitstream.ReadBytes(4);

            _bytesRead += 13;
            if (_bytesRead < _size)
            {
                Mp4Descriptor descriptor = CreateDescriptor(bitstream);
                _children.Add(descriptor);
                _bytesRead += descriptor.BytesRead;
            }
        }
Ejemplo n.º 6
0
        public static Mp4Descriptor CreateDescriptor(Mp4DataStream bitstream)
        {
            int tag       = (int)bitstream.ReadBytes(1);
            int bytesRead = 1;
            int size      = 0;
            int b         = 0;

            do
            {
                b      = (int)bitstream.ReadBytes(1);
                size <<= 7;
                size  |= b & 0x7f;
                bytesRead++;
            } while ((b & 0x80) == 0x80);
            Mp4Descriptor descriptor = new Mp4Descriptor(tag, size);

            switch (tag)
            {
            case MP4ES_DescriptorTag:
                descriptor.CreateESDescriptor(bitstream);
                break;

            case MP4DecoderConfigDescriptorTag:
                descriptor.CreateDecoderConfigDescriptor(bitstream);
                break;

            case MP4DecSpecificInfoDescriptorTag:
                descriptor.CreateDecSpecificInfoDescriptor(bitstream);
                break;

            default:
                break;
            }
            bitstream.SkipBytes(descriptor._size - descriptor._bytesRead);
            descriptor._bytesRead = bytesRead + descriptor._size;
            return(descriptor);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Loads M4ESDAtom atom from the input bitstream.
 /// </summary>
 /// <param name="bitstream">The input bitstream.</param>
 /// <returns>The number of bytes loaded.</returns>
 public long create_esd_atom(Mp4DataStream bitstream)
 {
     create_full_atom(bitstream);
     esd_descriptor = Mp4Descriptor.CreateDescriptor(bitstream);
     _bytesRead += esd_descriptor.BytesRead;
     return _bytesRead;
 }