コード例 #1
0
 public SmoothStreamChunk(StreamIndex parentStreamIndex, double fragmentIndex, int duration, int bitrate)
 {
     _parentIndex = parentStreamIndex;
     _fragmentIndex = fragmentIndex;
     _bitrate = bitrate;
     _duration = duration;
 }
コード例 #2
0
ファイル: ManifestParser.cs プロジェクト: mstoll/SmoothRunner
        public ConcurrentBag<StreamIndex> ParseManifest(Uri manifestUri)
        {
            Console.WriteLine("----------------------------------------------------------------------------------");
            Console.WriteLine("----------------------------------------------------------------------------------");
            Console.WriteLine("Start parsing manifest : {0}", manifestUri.ToString());

            List<SmoothStreamChunk> chunkList = new List<SmoothStreamChunk>();
            Stopwatch sw = new Stopwatch();
            sw.Start();
            string manifestXml = new WebClient().DownloadString(manifestUri);
            sw.Stop();

            ManifestDownloadTime = sw.Elapsed;

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(manifestXml);

            var ssMediaNode = xmlDoc.ChildNodes.Cast<XmlNode>().Where(n => n.Name == "SmoothStreamingMedia").FirstOrDefault();

            ConcurrentBag<StreamIndex> streams = new ConcurrentBag<StreamIndex>();

            var streamIndexNodes = ssMediaNode.ChildNodes.Cast<XmlNode>().Where(n => n.Name == "StreamIndex").ToList();

            foreach (var sIndexNode in streamIndexNodes)
            {
                StreamIndex si = new StreamIndex();

                si.StreamType = sIndexNode.Attributes["Type"].InnerText;
                si.Url = sIndexNode.Attributes["Url"].InnerText;

                if (!si.Url.StartsWith("http"))
                {
                    si.Url = new Uri(manifestUri, si.Url).ToString();
                }
                Console.WriteLine("----------------------------------------------------------------------------------");
                Console.WriteLine("Start parsing stream {0} of type {1}", si.Url, si.StreamType);

                var qualityLevelNodes = sIndexNode.ChildNodes.Cast<XmlNode>().Where(n => n.Name == "QualityLevel").ToList();

                foreach (var qlNode in qualityLevelNodes)
                {
                    int bitrate = Int32.Parse(qlNode.Attributes["Bitrate"].InnerText);
                    si.AddBitrate(bitrate);
                    Console.WriteLine("Found quality level {0}", bitrate);
                }

                Console.WriteLine("");

                var chunkNodes = sIndexNode.ChildNodes.Cast<XmlNode>().Where(n => n.Name == "c").ToList();
                double chunkDurationIndex = 0;

                foreach (var cNode in chunkNodes)
                {
                    int chunkDuration = Int32.Parse(cNode.Attributes["d"].InnerText);

                    if (chunkDurationIndex == 0)
                    {
                        foreach (var br in si.Bitrates)
                        {
                            si.AddChunk(0, chunkDuration, br);
                        }
                    }

                    if (cNode == chunkNodes.Last())
                    {
                        continue;
                    }

                    chunkDurationIndex += chunkDuration;

                    foreach (var br in si.Bitrates)
                    {
                        si.AddChunk(chunkDurationIndex, chunkDuration, br);
                    }
                }
                Console.WriteLine("There are {0} chunks to download the stream in all bitrates. Duration is {1}", si.Chunks.Count(), chunkDurationIndex);
                streams.Add(si);
                Console.WriteLine("----------------------------------------------------------------------------------");
            }

            return streams;
        }