/// <summary> /// Parses the manifest stream. /// </summary> /// <param name="manifestStream">The manifest stream being parsed.</param> private void ParseManifest(Stream manifestStream) { using (XmlReader reader = XmlReader.Create(manifestStream)) { if (reader.Read() && reader.IsStartElement(ManifestSmoothStreamingMediaElement)) { int majorVersion = reader.GetValueAsInt(ManifestMajorVersionAttribute).GetValueOrDefault(); int minorVersion = reader.GetValueAsInt(ManifestMinorVersionAttribute).GetValueOrDefault(); bool isLive = reader.GetValueAsBool(ManifestIsLiveAttribute).GetValueOrDefault(); int lookAheadFragmentCount = 0; int dvrWindowLength = 0; if (isLive) { lookAheadFragmentCount = reader.GetValueAsInt(ManifestLookAheadFragmentCountAttribute).GetValueOrDefault(); dvrWindowLength = reader.GetValueAsInt(ManifestDvrWindowLengthAttribute).GetValueOrDefault(); } ulong Timescale = reader.GetValueAsULong(TimeScaleAttribute).GetValueOrDefault(TicksPerSecond); ulong manifestDuration = reader.GetValueAsULong(ManifestDurationAttribute).GetValueOrDefault(); Guid protectionGuid = Guid.Empty; string protectionData = string.Empty; List <StreamInfo> streams = new List <StreamInfo>(); while (reader.Read()) { if (reader.Name == ManifestProtectionElement && reader.NodeType == XmlNodeType.Element) { reader.Read(); if (reader.Name == ManifestProtectionHeaderElement && reader.NodeType == XmlNodeType.Element) { protectionGuid = new Guid(reader.GetValue(ManifestProtectionSystemIDElement)); protectionData = reader.ReadElementContentAsString(); } } if (reader.Name == ManifestStreamIndexElement && reader.NodeType == XmlNodeType.Element) { string type = reader.GetValue(ManifestStreamIndexTypeAttribute); StreamInfo streamInfo = new StreamInfo(type); AddAttributes(reader, streamInfo); while (reader.Read()) { if (reader.Name == ManifestStreamIndexElement && reader.NodeType == XmlNodeType.EndElement) { break; } if ((reader.Name == "QualityLevel") && (reader.NodeType == XmlNodeType.Element)) { QualityLevel qualityLevel = new QualityLevel(); AddAttributes(reader, qualityLevel); AddCustomAttributes(reader, qualityLevel); streamInfo.QualityLevels.Add(qualityLevel); } if ((reader.Name == "c") && (reader.NodeType == XmlNodeType.Element)) { int? chunkId = reader.GetValueAsInt("n"); UInt64?time = reader.GetValueAsUInt64("t"); ulong? duration = reader.GetValueAsULong("d"); ulong? repetitions = reader.GetValueAsULong("r"); for (ulong i = 0; i < (repetitions.HasValue ? repetitions.Value : 1); i++) { Chunk chunk = new Chunk(chunkId, i == 0 ? time : null, duration); if (((!reader.IsEmptyElement && reader.Read()) && (reader.IsStartElement("f") && reader.Read())) && (reader.NodeType == XmlNodeType.Text)) { chunk.Value = reader.Value; } streamInfo.Chunks.Add(chunk); } } } streams.Add(streamInfo); } } streams.ToArray(); if (!isLive) { this.ManifestInfo = new ManifestInfo(majorVersion, minorVersion, manifestDuration, streams, protectionGuid, protectionData, Timescale); } else { this.ManifestInfo = new ManifestInfo(majorVersion, minorVersion, manifestDuration, isLive, lookAheadFragmentCount, dvrWindowLength, streams, protectionGuid, protectionData, Timescale); } } } }
/// <summary> /// Parses the manifest stream. /// </summary> /// <param name="manifestStream">The manifest stream being parsed.</param> private void ParseManifest(Stream manifestStream) { using (XmlReader reader = XmlReader.Create(manifestStream)) { if (reader.Read() && reader.IsStartElement(ManifestSmoothStreamingMediaElement)) { int majorVersion = reader.GetValueAsInt(ManifestMajorVersionAttribute).GetValueOrDefault(); int minorVersion = reader.GetValueAsInt(ManifestMinorVersionAttribute).GetValueOrDefault(); bool isLive = reader.GetValueAsBool(ManifestIsLiveAttribute).GetValueOrDefault(); int lookAheadFragmentCount = 0; int dvrWindowLength = 0; if (isLive) { lookAheadFragmentCount = reader.GetValueAsInt(ManifestLookAheadFragmentCountAttribute).GetValueOrDefault(); dvrWindowLength = reader.GetValueAsInt(ManifestDvrWindowLengthAttribute).GetValueOrDefault(); } ulong Timescale = reader.GetValueAsULong(TimeScaleAttribute).GetValueOrDefault(TicksPerSecond); ulong manifestDuration = reader.GetValueAsULong(ManifestDurationAttribute).GetValueOrDefault(); Guid protectionGuid = Guid.Empty; string protectionData = string.Empty; List<StreamInfo> streams = new List<StreamInfo>(); while (reader.Read()) { if (reader.Name == ManifestProtectionElement && reader.NodeType == XmlNodeType.Element) { reader.Read(); if (reader.Name == ManifestProtectionHeaderElement && reader.NodeType == XmlNodeType.Element) { protectionGuid = new Guid(reader.GetValue(ManifestProtectionSystemIDElement)); protectionData = reader.ReadElementContentAsString(); } } if (reader.Name == ManifestStreamIndexElement && reader.NodeType == XmlNodeType.Element) { string type = reader.GetValue(ManifestStreamIndexTypeAttribute); StreamInfo streamInfo = new StreamInfo(type); AddAttributes(reader, streamInfo); while (reader.Read()) { if (reader.Name == ManifestStreamIndexElement && reader.NodeType == XmlNodeType.EndElement) { break; } if ((reader.Name == "QualityLevel") && (reader.NodeType == XmlNodeType.Element)) { QualityLevel qualityLevel = new QualityLevel(); AddAttributes(reader, qualityLevel); AddCustomAttributes(reader, qualityLevel); streamInfo.QualityLevels.Add(qualityLevel); } if ((reader.Name == "c") && (reader.NodeType == XmlNodeType.Element)) { int? chunkId = reader.GetValueAsInt("n"); UInt64? time = reader.GetValueAsUInt64("t"); ulong? duration = reader.GetValueAsULong("d"); ulong? repetitions = reader.GetValueAsULong("r"); for (ulong i = 0; i < (repetitions.HasValue ? repetitions.Value : 1); i++) { Chunk chunk = new Chunk(chunkId, i == 0 ? time : null, duration); if (((!reader.IsEmptyElement && reader.Read()) && (reader.IsStartElement("f") && reader.Read())) && (reader.NodeType == XmlNodeType.Text)) { chunk.Value = reader.Value; } streamInfo.Chunks.Add(chunk); } } } streams.Add(streamInfo); } } streams.ToArray(); if (!isLive) { this.ManifestInfo = new ManifestInfo(majorVersion, minorVersion, manifestDuration, streams, protectionGuid, protectionData,Timescale); } else { this.ManifestInfo = new ManifestInfo(majorVersion, minorVersion, manifestDuration, isLive, lookAheadFragmentCount, dvrWindowLength, streams, protectionGuid, protectionData,Timescale); } } } }