Ejemplo n.º 1
0
        public void Parse(XmlNodeEx nodeManifest, string rootURL = "", string idPrefix = "", int nestedBitrate = 0)
        {
            id           = nodeManifest.GetText("id");
            label        = nodeManifest.GetText("label");
            lang         = nodeManifest.GetText("lang");
            duration     = nodeManifest.GetFloat("duration");
            startTime    = nodeManifest.GetDateTime("startTime");
            mimeType     = nodeManifest.GetText("mimeType");
            streamType   = nodeManifest.GetText("streamType");
            deliveryType = nodeManifest.GetText("deliveryType");
            baseURL      = nodeManifest.GetText("baseURL");
            urlIncludesFMSApplicationInstance = nodeManifest.GetAttributeBoolean("urlIncludesFMSApplicationInstance");
            if (string.IsNullOrEmpty(baseURL))
            {
                baseURL = rootURL;
            }
            baseURL = URL.normalizePathForURL(baseURL, false);

            XmlNodeEx nodeDVR = nodeManifest.GetChildNode("dvrInfo") as XmlNodeEx;

            dvrInfo = (nodeDVR != null) ? new DVRInfo(nodeDVR) : null;

            // cueInfo
            cueInfos.Clear();
            List <XmlNodeEx> cueInfoNodes = nodeManifest.GetChildNodesByName("cueInfo");

            foreach (XmlNodeEx nodeCueInfo in cueInfoNodes)
            {
                string  cueInfoId = nodeCueInfo.GetAttributeStr("id", F4MUtils.GLOBAL_ELEMENT_ID);
                CueInfo cueInfo   = new CueInfo(cueInfoId);
                foreach (XmlNodeEx node in nodeCueInfo.GetChildNodesByName("cue"))
                {
                    cueInfo.Cues.Add(new Cue(node, baseURL, idPrefix));
                }
                cueInfos.Add(cueInfo);
            }

            media.Clear();
            alternativeMedia.Clear();
            drmAdditionalHeaders.Clear();
            bootstrapInfos.Clear();

            foreach (XmlNode childNode in nodeManifest.ChildNodes)
            {
                XmlNodeEx childNodeEx = childNode as XmlNodeEx;
                if (childNodeEx == null)
                {
                    continue;
                }
                switch (childNodeEx.Name)
                {
                case "media":
                    Media mediaItem = new Media(childNodeEx, baseURL, idPrefix, nestedBitrate);
                    if (mediaItem.bitrate == 0)
                    {
                        mediaItem.bitrate = nodeManifest.GetAttributeInt("bitrate");
                    }
                    if (mediaItem.alternate)
                    {
                        alternativeMedia.Add(mediaItem);
                    }
                    else
                    {
                        media.Add(mediaItem);
                    }
                    break;

                case "drmAdditionalHeader":
                    drmAdditionalHeaders.Add(new DRMAdditionalHeader(childNodeEx, baseURL, idPrefix));
                    break;

                case "bootstrapInfo":
                    bootstrapInfos.Add(new BootstrapInfo(childNodeEx, baseURL, idPrefix));
                    break;
                }
            }

            XmlNodeEx nodeBEF = nodeManifest.GetChildNode("bestEffortFetchInfo") as XmlNodeEx;

            bestEffortFetchInfo = (nodeBEF != null) ? new BestEffortFetchInfo(nodeBEF) : null;

            // Adaptive sets search
            List <XmlNodeEx> adaptiveSet = nodeManifest.GetChildNodesByName("adaptiveSet");

            foreach (XmlNodeEx nodeSet in adaptiveSet)
            {
                string           alternate  = nodeSet.GetAttributeStr("alternate");
                string           audioCodec = nodeSet.GetAttributeStr("audioCodec");
                string           label      = nodeSet.GetAttributeStr("label");
                string           lang       = nodeSet.GetAttributeStr("lang");
                string           type       = nodeSet.GetAttributeStr("type");
                List <XmlNodeEx> mediaInSet = nodeSet.GetChildNodesByName("media");
                foreach (XmlNodeEx nodeMedia in mediaInSet)
                {
                    Media mediaItem = new Media(nodeMedia, baseURL, idPrefix, nestedBitrate);
                    if (mediaItem.bitrate == 0)
                    {
                        mediaItem.bitrate = nodeManifest.GetAttributeInt("bitrate");
                    }
                    if (!string.IsNullOrEmpty(alternate))
                    {
                        mediaItem.alternate = true;
                    }
                    if (!string.IsNullOrEmpty(audioCodec) && string.IsNullOrEmpty(mediaItem.audioCodec))
                    {
                        mediaItem.audioCodec = audioCodec;
                    }
                    if (!string.IsNullOrEmpty(label) && string.IsNullOrEmpty(mediaItem.label))
                    {
                        mediaItem.label = label;
                    }
                    if (!string.IsNullOrEmpty(lang) && string.IsNullOrEmpty(mediaItem.lang))
                    {
                        mediaItem.lang = lang;
                    }
                    if (!string.IsNullOrEmpty(type) && string.IsNullOrEmpty(mediaItem.type))
                    {
                        mediaItem.type = type;
                    }

                    if (mediaItem.alternate)
                    {
                        alternativeMedia.Add(mediaItem);
                    }
                    else
                    {
                        media.Add(mediaItem);
                    }
                }
            }

            GenerateRTMPBaseURL();
        }