{"record":{"id":"e94ca58d390c8f63","repo":"subhra74/xdm","slug":"both-period-start-and-duration-is-missing","errorCode":null,"errorMessage":"Both period start and duration is missing","messagePattern":"Both period start and duration is missing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/XDM/XDM.Core/MediaParser/Dash/MpdParser.cs","lineNumber":378,"sourceCode":"\r\n        public static IList<long> CalculatePeriodDurationsIfMissing(XmlNodeList periods, long mediaPresentationDuration)\r\n        {\r\n            var stack = new Stack<XmlNode>();\r\n            foreach (XmlNode node in periods)\r\n            {\r\n                stack.Push(node);\r\n            }\r\n            var list = new List<long>(periods.Count);\r\n            var last = mediaPresentationDuration;\r\n            var count = stack.Count;\r\n            for (int i = 0; i < count; i++)\r\n            {\r\n                var node = stack.Pop();\r\n                var sduration = node.Attributes[\"duration\"]?.Value;\r\n                var sstart = node.Attributes[\"start\"]?.Value;\r\n                if (sstart == null && sduration == null)\r\n                {\r\n                    throw new Exception(\"Both period start and duration is missing\");\r\n                }\r\n                if (sduration != null)\r\n                {\r\n                    var duration = DashUtil.ParseXsDuration(sduration);\r\n                    list.Add(duration);\r\n                    last = mediaPresentationDuration - duration;\r\n                    continue;\r\n                }\r\n                if (sstart == null && i == stack.Count - 1)\r\n                {\r\n                    sstart = \"PT0S\";\r\n                }\r\n                var start = DashUtil.ParseXsDuration(sstart);\r\n                list.Add(last - start);\r\n                last = start;\r\n            }\r\n            list.Reverse();\r\n            return list;\r","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/subhra74/xdm/blob/1ca5a25aae007826c859c81bea494e7c102e1242/app/XDM/XDM.Core/MediaParser/Dash/MpdParser.cs#L360-L396","documentation":"When an MPD contains multiple <Period> elements, CalculatePeriodDurationsIfMissing computes each period's duration from its start/duration attributes. If a period defines neither start nor duration, the duration cannot be derived, so the method throws. This is an invariant check required to compute period boundaries for the segment list.","triggerScenarios":"Parsing a multi-period MPD (periods.Count > 1) in which at least one Period element lacks both a start attribute and a duration attribute, and the duration can't be inferred from the next period or mediaPresentationDuration.","commonSituations":"Hand-edited or programmatically generated multi-period manifests missing timing attributes; ad-inserted streams where dynamic periods are added without start times; manifests relying on features (e.g. Period@id continuity / implicit timing) this parser doesn't implement.","solutions":["Add explicit start and/or duration attributes to every Period element in the manifest.","If you control manifest generation, always emit mediaPresentationDuration plus per-period timing.","Catch the error and reject the multi-period manifest, directing users to a single-period VOD rendition.","Check whether the source manifest is actually valid with a DASH validator (e.g. DASH-IF conformance tool)."],"exampleFix":"// before\n<Period id=\"p2\"></Period>\n\n// after\n<Period id=\"p2\" start=\"PT30S\" duration=\"PT60S\"></Period>","handlingStrategy":"validation","validationCode":"var doc = new XmlDocument(); doc.LoadXml(mpdXml);\nforeach (XmlNode p in doc.SelectNodes(\"//*[local-name()='Period']\"))\n    if (p.Attributes[\"start\"] == null && p.Attributes[\"duration\"] == null)\n        throw new Exception(\"Period missing both start and duration\");","typeGuard":null,"tryCatchPattern":"try { return MpdParser.Parse(url, null); }\ncatch (Exception ex) when (ex.Message.Contains(\"Both period start and duration is missing\"))\n{ throw new InvalidManifestException(\"Multi-period MPD lacks timing attributes\", ex); }","preventionTips":["Only feed multi-period manifests with explicit Period@start/@duration","Fix manifest generation to always emit timing attributes plus mediaPresentationDuration","Validate multi-period manifests with the DASH-IF tool before use"],"tags":["dash","manifest-parsing","period-duration","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"1ca5a25aae007826c859c81bea494e7c102e1242","analyzedAt":"2026-09-13T20:37:40.968Z","contentChangedAt":"2026-09-13T20:37:40.968Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}