Exemple #1
0
        public async Task Start(string baseurl, string guid, Manifest manifest, Media media, CancellationToken token, IProgress <double> progress)
        {
            this.media     = media;
            this.guid      = guid;
            this.baseurl   = baseurl;
            this.bootstrap = media.Info.Info;
            this.manifest  = manifest;
            await InitFile();
            await DoNextFragment();

            progress.Report((double)bootstrap.CurrentFragmentWrite * 100D / (double)bootstrap.FragmentCount);
            token.ThrowIfCancellationRequested();
            await ThreadProcessor(token, progress);

            token.ThrowIfCancellationRequested();
        }
        public bool ReadBootStrap(BootStrap info)
        {
            info.Version          = ReadByte();
            info.Flags            = EReadInt24();
            info.BootStrapVersion = EReadInt32();
            byte flags = ReadByte();

            info.ProfileType = (flags & 0xc0) >> 6;
            if ((flags & 0x20) == 0x20)
            {
                info.Live        = true;
                info.HasMetadata = false;
            }
            info.IsUpdate = ((flags & 0x10) == 0x10);
            if (!info.IsUpdate)
            {
                info.SegmentTables  = new Dictionary <int, Segment>();
                info.FragmentTables = new Dictionary <int, Fragment>();
            }
            info.Timescale           = EReadInt32();
            info.CurrentMediaTime    = EReadInt64();
            info.SmpteTimeCodeOffset = EReadInt64();
            info.MovieIdentifier     = EReadString();
            int cnt = ReadByte();

            info.ServerEntryTable = new List <string>();
            for (int x = 0; x < cnt; x++)
            {
                info.ServerEntryTable.Add(EReadString());
            }
            cnt = ReadByte();
            info.QualityEntryTable = new List <string>();
            for (int x = 0; x < cnt; x++)
            {
                info.QualityEntryTable.Add(EReadString());
            }
            info.DrmData  = ReadString();
            info.MetaData = ReadString();
            cnt           = ReadByte();
            for (int x = 0; x < cnt; x++)
            {
                string name;
                long   left = ReadHeader(out name);
                if (name == "asrt")
                {
                    ReadSegment().ToList().ForEach(a => info.SegmentTables[a.Key] = a.Value);
                }
                else
                {
                    BaseStream.Seek(left, SeekOrigin.Current);
                }
            }
            cnt = ReadByte();
            for (int x = 0; x < cnt; x++)
            {
                string name;
                long   left = ReadHeader(out name);
                if (name == "afrt")
                {
                    ReadFragment().ToList().ForEach(a => info.FragmentTables[a.Key] = a.Value);
                }
                else
                {
                    BaseStream.Seek(left, SeekOrigin.Current);
                }
            }
            info.SegmentTables  = info.SegmentTables.OrderBy(a => a.Key).ToDictionary(a => a.Key, a => a.Value);
            info.FragmentTables = info.FragmentTables.OrderBy(a => a.Key).ToDictionary(a => a.Key, a => a.Value);
            info.InitFragments();
            return(true);
        }