@@ -272,15 +272,15 @@ func LiveMPD(a *asset, mpdName string, cfg *ResponseConfig, drmCfg *drm.DrmConfi
272272 }
273273 switch templateType {
274274 case timeLineTime :
275- err := adjustAdaptationSetForTimelineTime (cfg , se , as )
275+ err := adjustAdaptationSetForTimeline (cfg , se , as )
276276 if err != nil {
277277 return nil , fmt .Errorf ("adjustASForTimelineTime: %w" , err )
278278 }
279279 if asIdx == 0 {
280280 mpd .PublishTime = m .ConvertToDateTime (calcPublishTime (cfg , se .lsi ))
281281 }
282282 case timeLineNumber :
283- err := adjustAdaptationSetForTimelineNr (cfg , se , as )
283+ err := adjustAdaptationSetForTimeline (cfg , se , as )
284284 if err != nil {
285285 return nil , fmt .Errorf ("adjustASForTimelineNr: %w" , err )
286286 }
@@ -588,64 +588,41 @@ func setOffsetInAdaptationSet(cfg *ResponseConfig, as *m.AdaptationSetType) (ato
588588 return atoMS , nil
589589}
590590
591- func adjustAdaptationSetForTimelineTime (cfg * ResponseConfig , se segEntries , as * m.AdaptationSetType ) error {
591+ func adjustAdaptationSetForTimeline (cfg * ResponseConfig , se segEntries , as * m.AdaptationSetType ) error {
592592 if as .SegmentTemplate .SegmentTimeline == nil {
593593 as .SegmentTemplate .SegmentTimeline = & m.SegmentTimelineType {}
594594 }
595- as . SegmentTemplate . StartNumber = nil
595+
596596 as .SegmentTemplate .Duration = nil
597- as .SegmentTemplate .Media = strings .ReplaceAll (as .SegmentTemplate .Media , "$Number$" , "$Time$" )
598597 as .SegmentTemplate .Timescale = Ptr (se .mediaTimescale )
599598
600- // Check if pattern mode is enabled and this is audio
601- if cfg .SegTimelineMode == SegTimelineModePattern && as .ContentType == "audio" {
602- // Try to detect and apply pattern based on cyclic alignment
603- if patternSTL := detectAndApplyPattern (se ); patternSTL != nil {
604- as .SegmentTemplate .SegmentTimeline = patternSTL
605- // Add EssentialProperty for pattern support
606- as .EssentialProperties = append (as .EssentialProperties , & m.DescriptorType {
607- SchemeIdUri : "urn:mpeg:dash:pattern:2024" ,
608- })
609- return nil
610- }
611- }
599+ isNumberBased := cfg .SegTimelineMode == SegTimelineModeNr || cfg .SegTimelineMode == SegTimelineModeNrPattern
600+ isPatternBased := cfg .SegTimelineMode == SegTimelineModePattern || cfg .SegTimelineMode == SegTimelineModeNrPattern
612601
613- // Default: use regular segment entries
614- as .SegmentTemplate .SegmentTimeline . S = se . entries
615- return nil
616- }
617-
618- func adjustAdaptationSetForTimelineNr ( cfg * ResponseConfig , se segEntries , as * m. AdaptationSetType ) error {
619- if as .SegmentTemplate .SegmentTimeline == nil {
620- as .SegmentTemplate .SegmentTimeline = & m. SegmentTimelineType {}
602+ if isNumberBased {
603+ as .SegmentTemplate .Media = strings . ReplaceAll ( as . SegmentTemplate . Media , "$Time$" , "$Number$" )
604+ if se . startNr >= 0 {
605+ as . SegmentTemplate . StartNumber = Ptr ( uint32 ( se . startNr ))
606+ }
607+ } else {
608+ as .SegmentTemplate .Media = strings . ReplaceAll ( as . SegmentTemplate . Media , "$Number$" , "$Time$" )
609+ as .SegmentTemplate .StartNumber = nil
621610 }
622- as .SegmentTemplate .StartNumber = nil
623- as .SegmentTemplate .Duration = nil
624- as .SegmentTemplate .Media = strings .ReplaceAll (as .SegmentTemplate .Media , "$Time$" , "$Number$" )
625- as .SegmentTemplate .Timescale = Ptr (se .mediaTimescale )
626611
627- // Check if pattern mode is enabled and this is audio
628- if cfg .SegTimelineMode == SegTimelineModeNrPattern && as .ContentType == "audio" {
612+ if as .ContentType == "audio" && isPatternBased {
629613 // Try to detect and apply pattern based on cyclic alignment
630614 if patternSTL := detectAndApplyPattern (se ); patternSTL != nil {
631615 as .SegmentTemplate .SegmentTimeline = patternSTL
632616 // Add EssentialProperty for pattern support
633617 as .EssentialProperties = append (as .EssentialProperties , & m.DescriptorType {
634618 SchemeIdUri : "urn:mpeg:dash:pattern:2024" ,
635619 })
636- if se .startNr >= 0 {
637- as .SegmentTemplate .StartNumber = Ptr (uint32 (se .startNr ))
638- }
639620 return nil
640621 }
641622 }
642623
643624 // Default: use regular segment entries
644625 as .SegmentTemplate .SegmentTimeline .S = se .entries
645-
646- if se .startNr >= 0 {
647- as .SegmentTemplate .StartNumber = Ptr (uint32 (se .startNr ))
648- }
649626 return nil
650627}
651628
0 commit comments