Пример #1
0
        public override void Parse(BoxInfo bi, HDSBinaryReader br)
        {
            base.Parse(bi, br);

            uint sizes            = br.ReadByte();
            bool longIdFields     = ((sizes & AFRA_MASK_LONG_ID) > 0);
            bool longOffsetFields = ((sizes & AFRA_MASK_LONG_OFFSET) > 0);
            bool globalEntries    = ((sizes & AFRA_MASK_GLOBAL_ENTRIES) > 0);

            timeScale = br.ReadUInt32();

            localRandomAccessEntries.Clear();
            uint entryCount = br.ReadUInt32();

            for (uint i = 0; i < entryCount; i++)
            {
                LocalRandomAccessEntry lrae = new LocalRandomAccessEntry();
                lrae.Parse(br, longOffsetFields);
                localRandomAccessEntries.Add(lrae);
            }

            globalRandomAccessEntries.Clear();
            if (globalEntries)
            {
                entryCount = br.ReadUInt32();
                for (int i = 0; i < entryCount; i++)
                {
                    GlobalRandomAccessEntry grae = new GlobalRandomAccessEntry();
                    grae.Parse(br, longIdFields, longOffsetFields);
                    globalRandomAccessEntries.Add(grae);
                }
            }
        }
Пример #2
0
        public static BoxInfo getNextBoxInfo(HDSBinaryReader br)
        {
            if (!br.BaseStream.CanRead || (br.BytesAvailable < F4FConstants.FIELD_SIZE_LENGTH + F4FConstants.FIELD_TYPE_LENGTH))
            {
                return(null);
            }
            uint   size   = br.ReadUInt32();
            string type   = br.ReadUtfBytes(F4FConstants.FIELD_TYPE_LENGTH);
            uint   length = F4FConstants.FIELD_SIZE_LENGTH + F4FConstants.FIELD_TYPE_LENGTH;

            if (size == F4FConstants.FLAG_USE_LARGE_SIZE)
            {
                size    = (uint)br.ReadUInt64();
                length += F4FConstants.FIELD_LARGE_SIZE_LENGTH;
            }

            if (type == F4FConstants.EXTENDED_TYPE)
            {
                // Read past the extended type.
                br.Position += F4FConstants.FIELD_EXTENDED_TYPE_LENGTH;
                length      += F4FConstants.FIELD_EXTENDED_TYPE_LENGTH;
            }

            return(new BoxInfo(size, type, length));
        }
        public void Parse(HDSBinaryReader br, bool longIdFields, bool longOffsetFields)
        {
            time = br.ReadUInt64();

            if (longIdFields)
            {
                segment  = br.ReadUInt32();
                fragment = br.ReadUInt32();
            }
            else
            {
                segment  = br.ReadUInt16();
                fragment = br.ReadUInt16();
            }

            if (longOffsetFields)
            {
                afraOffset     = br.ReadUInt64();
                offsetFromAfra = br.ReadUInt64();
            }
            else
            {
                afraOffset     = br.ReadUInt32();
                offsetFromAfra = br.ReadUInt32();
            }
        }
Пример #4
0
        public static FLVTag Parse(HDSBinaryReader br)
        {
            if (!br.BaseStream.CanRead || (br.BytesAvailable <= TAG_HEADER_BYTE_COUNT))
            {
                return(null);
            }
            FLVTag tag;

            byte    b    = br.ReadByte();
            TagType type = (TagType)(b & 0x1f);

            switch (type)
            {
            case TagType.AUDIO:
            case TagType.AKAMAI_ENC_AUDIO: tag = new FLVTagAudio(type); break;

            case TagType.VIDEO:
            case TagType.AKAMAI_ENC_VIDEO: tag = new FLVTagVideo(type); break;

            default:                       tag = new FLVTag(type);      break;
            }
            tag.Filter = (b & 0x20) > 0;
            uint dataSize = br.ReadUInt24();

            tag.Timestamp = br.ReadUInt24() + (uint)(br.ReadByte() << 24);
            uint StreamID = br.ReadUInt24();

            tag.Data = br.ReadBytes((int)dataSize);
            if (br.BytesAvailable > 3)
            {
                tag.SizeOfPreviousPacket = br.ReadUInt32();
            }
            return(tag);
        }
Пример #5
0
        public static List <Box> GetBoxes(byte[] data, string boxType = "")
        {
            List <Box> boxes = new List <Box>();

            System.IO.MemoryStream stream = null;
            try {
                stream = new System.IO.MemoryStream(data);
                using (HDSBinaryReader br = new HDSBinaryReader(stream)) {
                    stream = null;
                    BoxInfo bi = BoxInfo.getNextBoxInfo(br);
                    while (bi != null)
                    {
                        if (!string.IsNullOrEmpty(boxType) && bi.Type != boxType)
                        {
                            bi.Type = ""; // for skip other boxes
                        }
                        switch (bi.Type)
                        {
                        case F4FConstants.BOX_TYPE_ABST:
                            AdobeBootstrapBox abst = new AdobeBootstrapBox();
                            abst.Parse(bi, br);
                            boxes.Add(abst);
                            break;

                        case F4FConstants.BOX_TYPE_AFRA:
                            AdobeFragmentRandomAccessBox arfa = new AdobeFragmentRandomAccessBox();
                            arfa.Parse(bi, br);
                            boxes.Add(arfa);
                            break;

                        case F4FConstants.BOX_TYPE_MDAT:
                            MediaDataBox mdat = new MediaDataBox();
                            mdat.Parse(bi, br);
                            boxes.Add(mdat);
                            break;

                        default:
                            br.Position += bi.Size - bi.Length;
                            break;
                        }
                        bi = BoxInfo.getNextBoxInfo(br);
                        if (bi != null && bi.Size <= 0)
                        {
                            break;
                        }
                    }
                }
            } finally {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }
            return(boxes);
        }
Пример #6
0
        public void Parse(HDSBinaryReader br)
        {
            firstFragment   = br.ReadUInt32();
            durationAccrued = br.ReadUInt64();
            duration        = br.ReadUInt32();

            if (duration == 0)
            {
                discontinuityIndicator = br.ReadByte();
            }
        }
 public void Parse(HDSBinaryReader br, bool longOffsetFields)
 {
     time = br.ReadUInt64();
     if (longOffsetFields)
     {
         offset = br.ReadUInt64();
     }
     else
     {
         offset = br.ReadUInt32();
     }
 }
Пример #8
0
        public static void GetVideoAndAudioTags(TagsStore tagsStore, byte[] data)
        {
            MemoryStream stream = null;

            try {
                stream = new MemoryStream(data);
                using (HDSBinaryReader br = new HDSBinaryReader(stream)) {
                    stream = null;
                    FLVTag tag = Parse(br);
                    while (tag != null)
                    {
                        // only audio or video and skipping small sized packet
                        if (tag.DataSize > 2 && (tag.Type == TagType.AUDIO || tag.Type == TagType.AKAMAI_ENC_AUDIO || tag.Type == TagType.VIDEO || tag.Type == TagType.AKAMAI_ENC_VIDEO))
                        {
                            if (!tagsStore.hasAudio && tag is FLVTagAudio audioTag)
                            {
                                tagsStore.hasAudio      = true;
                                tagsStore.AudioFormat   = audioTag.SoundFormat;
                                tagsStore.AudioRate     = audioTag.SoundRate;
                                tagsStore.AudioChannels = audioTag.SoundChannels;
                            }

                            if (!tagsStore.hasVideo && tag is FLVTagVideo videoTag)
                            {
                                tagsStore.hasVideo   = true;
                                tagsStore.VideoCodec = videoTag.CodecID;
                            }

                            tagsStore.Enqueue(tag);

                            if (tag.Timestamp > tagsStore.lastTS)
                            {
                                tagsStore.lastTS = tag.Timestamp;
                            }
                            if (!tagsStore.isAkamaiEncrypted && tag.IsAkamaiEncrypted)
                            {
                                tagsStore.isAkamaiEncrypted = true;
                            }
                        }
                        tag = Parse(br);
                    }
                }
            } finally {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }
        }
Пример #9
0
        public override void Parse(BoxInfo bi, HDSBinaryReader br)
        {
            base.Parse(bi, br);

            qualitySegmentURLModifiers.Clear();
            uint qualityEntryCount = br.ReadByte();

            for (uint i = 0; i < qualityEntryCount; i++)
            {
                qualitySegmentURLModifiers.Add(br.ReadString());
            }

            uint entryCount = br.ReadUInt32();

            for (uint i = 0; i < entryCount; i++)
            {
                addSegmentFragmentPair(new SegmentFragmentPair(br.ReadUInt32(), br.ReadUInt32()));
            }
        }
Пример #10
0
        public override void Parse(BoxInfo bi, HDSBinaryReader br)
        {
            base.Parse(bi, br);

            timeScale = br.ReadUInt32();

            qualitySegmentURLModifiers.Clear();
            uint qualityEntryCount = br.ReadByte();

            for (uint i = 0; i < qualityEntryCount; i++)
            {
                qualitySegmentURLModifiers.Add(br.ReadString());
            }

            uint entryCount = br.ReadUInt32();

            for (uint i = 0; i < entryCount; i++)
            {
                FragmentDurationPair fdp = new FragmentDurationPair();
                fdp.Parse(br);
                fragmentDurationPairs.Add(fdp);
            }
        }
Пример #11
0
        public static List <FLVTag> GetTags(byte[] data)
        {
            List <FLVTag> tags   = new List <FLVTag>();
            MemoryStream  stream = null;

            try {
                stream = new MemoryStream(data);
                using (HDSBinaryReader br = new HDSBinaryReader(stream)) {
                    stream = null;
                    FLVTag tag = Parse(br);
                    while (tag != null)
                    {
                        tags.Add(tag);
                        tag = Parse(br);
                    }
                }
            } finally {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }
            return(tags);
        }
Пример #12
0
 public override void Parse(BoxInfo bi, HDSBinaryReader br)
 {
     base.Parse(bi, br);
     Version = br.ReadByte();
     Flags   = br.ReadUInt24();
 }
Пример #13
0
 public virtual void Parse(BoxInfo bi, HDSBinaryReader br)
 {
     Size   = bi.Size;
     Type   = bi.Type;
     Length = bi.Length;
 }
Пример #14
0
 public override void Parse(BoxInfo bi, HDSBinaryReader br)
 {
     base.Parse(bi, br);
     data = br.ReadBytes((int)(Size - Length));
 }
Пример #15
0
        public override void Parse(BoxInfo bi, HDSBinaryReader br)
        {
            base.Parse(bi, br);

            bootstrapVersion = br.ReadUInt32();

            byte temp = br.ReadByte();

            profile = (uint)(temp >> 6);
            live    = ((temp & 0x20) > 0);
            update  = ((temp & 0x01) > 0);

            timeScale           = br.ReadUInt32();
            currentMediaTime    = br.ReadUInt64();
            smpteTimeCodeOffset = br.ReadUInt64();
            movieIdentifier     = br.ReadString();

            serverBaseURLs.Clear();
            int serverEntryCount = br.ReadByte();

            for (int i = 0; i < serverEntryCount; i++)
            {
                serverBaseURLs.Add(br.ReadString());
            }

            qualitySegmentURLModifiers.Clear();
            int qualityEntryCount = br.ReadByte();

            for (int i = 0; i < qualityEntryCount; i++)
            {
                qualitySegmentURLModifiers.Add(br.ReadString());
            }

            drmData  = br.ReadString();
            metadata = br.ReadString();

            segmentRunTables.Clear();
            uint segmentRunTableCount = br.ReadByte();

            for (uint i = 0; i < segmentRunTableCount; i++)
            {
                BoxInfo boxInfo = BoxInfo.getNextBoxInfo(br);
                if (boxInfo == null)
                {
                    break;
                }
                if (boxInfo.Type == F4FConstants.BOX_TYPE_ASRT)
                {
                    AdobeSegmentRunTable asrt = new AdobeSegmentRunTable();
                    asrt.Parse(boxInfo, br);
                    segmentRunTables.Add(asrt);
                }
            }

            fragmentRunTables.Clear();
            uint fragmentRunTableCount = br.ReadByte();

            for (uint i = 0; i < fragmentRunTableCount; i++)
            {
                BoxInfo boxInfo = BoxInfo.getNextBoxInfo(br);
                if (boxInfo == null)
                {
                    break;
                }
                if (boxInfo.Type == F4FConstants.BOX_TYPE_AFRT)
                {
                    AdobeFragmentRunTable afrt = new AdobeFragmentRunTable();
                    afrt.Parse(boxInfo, br);
                    fragmentRunTables.Add(afrt);
                }
            }

            // Check if live stream is still live
            if (live && (fragmentRunTables.Count > 0) && ContentComplete())
            {
                live = false;
                RemoveLastFragment();
            }
        }