/// <summary> /// Check if the manifest structure is valid /// </summary> /// <param name="Manifest"></param> /// <param name="SegmentUrl"></param> /// <returns></returns> private bool checkStructure(MPDtype Manifest, out string SegmentUrl) { try { //check manifest data structure if (Manifest != null && Manifest.Period != null && Manifest.Period.Length > 0) { if (Manifest.Period[0] != null && Manifest.Period[0].AdaptationSet != null && Manifest.Period[0].AdaptationSet.Length > 0) { if (Manifest.Period[0].AdaptationSet[0] != null && Manifest.Period[0].AdaptationSet[0].SegmentTemplate != null) { if (Manifest.Period[0].AdaptationSet[0].Representation != null && Manifest.Period[0].AdaptationSet[0].Representation.Length > 0) { if (Manifest.Period[0].AdaptationSet[0].Representation[0] != null) { //get properties from manifest for the segment url var _segmentUrl = Manifest.Period[0].AdaptationSet[0].SegmentTemplate.media; var _bandwidth = Manifest.Period[0].AdaptationSet[0].Representation[0].bandwidth.ToString(); //some replacing jobs for the segment url _segmentUrl = _segmentUrl.Replace("$Bandwidth$", _bandwidth); _segmentUrl = _segmentUrl.Replace("$Time$", "0"); SegmentUrl = _segmentUrl; return(true); } } } } } SegmentUrl = string.Empty; return(false); } catch (Exception ex) { Logger.WriteError("checkStructure", ex); throw ex; } }
public static async Task XMLData_AppParserSysParser_same_OK() { if (parsedMpds.Count == 0) { HasRepresentation_OK(); } bool allTestsResult = true; foreach (var item in parsedMpds) { // Schema Name replacement is done in "raw XML string". // Schema/namespace modifications seem to work... oddly and throwing // exception if schema name already exists in XSD file (WTF?) // so the simplest way is to perform checks on raw XML string. // Ugly... string tmpXml = string.Copy(item.rawXML); if (tmpXml.IndexOf(schema, StringComparison.Ordinal) == -1) { int idx = tmpXml.IndexOf(schema, StringComparison.OrdinalIgnoreCase); if (idx == -1) { System.Diagnostics.Debug.WriteLine( $"Incorrect input schema in {item.url}. caseless urn:mpeg:dash:schema:mpd:2011 not found. Ignoring TC"); continue; } //Case mismatch. Move everything to lower case tmpXml = tmpXml.Replace(tmpXml.Substring(idx, schema.Length), schema); } // ok... so we are "re-parsing" internal xml here... // but do it from original data (not schema replaced one) MpdParser.Node.DASH IntMPD = await Document.FromTextInternal(item.rawXML, item.url); XmlSerializer serializer = new XmlSerializer(typeof(MPDtype)); System.IO.StringReader reader = new System.IO.StringReader(tmpXml); //Stream XMLStream = GenerateStreamFromString(tmpxml); XmlReader XReader = XmlReader.Create(reader); // Call the Deserialize method to restore the object's state. MPDtype ExtMPD = null; try { ExtMPD = (MPDtype)serializer.Deserialize(XReader); } catch (Exception e) { System.Diagnostics.Debug.WriteLine($"Unparsable MPD (System Parser): {item.url}"); System.Diagnostics.Debug.WriteLine($"Exception: {e.Message} {e.Source}"); System.Diagnostics.Debug.WriteLine($"Exception: {e.InnerException}"); System.Diagnostics.Debug.WriteLine($"Unparsable MPD will NOT influence final result as comparison is not possible"); continue; } MpdParser.Node.DASH itemFromExtMPD = DASHConverter.Convert(ExtMPD, item.url); System.Diagnostics.Debug.WriteLine($"Checking URL: {item.url} ..."); bool res = DASHConverter.Same(itemFromExtMPD, "Sys Parser", IntMPD, "App Parser"); if (item.ignore_mpd_comparison) { System.Diagnostics.Debug.WriteLine($"Same: {res} (Result is ignored by JSON specification"); } else { allTestsResult &= res; System.Diagnostics.Debug.WriteLine($"Same: {res}"); } System.Diagnostics.Debug.WriteLine($"Done URL: {item.url}"); } System.Diagnostics.Debug.WriteLine($"All MPDs same: {allTestsResult}"); Assert.IsTrue(allTestsResult); }