demux: adaptive: check vod template limit
authorFrancois Cartegnie <fcvlcdev@free.fr>
Mon, 25 May 2020 12:04:18 +0000 (14:04 +0200)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Mon, 25 May 2020 13:10:54 +0000 (15:10 +0200)
modules/demux/adaptive/playlist/BasePeriod.cpp
modules/demux/adaptive/playlist/BasePeriod.h
modules/demux/adaptive/playlist/SegmentInformation.cpp
modules/demux/adaptive/playlist/SegmentInformation.hpp

index 971851c..94295ff 100644 (file)
@@ -99,3 +99,8 @@ vlc_tick_t BasePeriod::getPeriodStart() const
 {
     return startTime.Get();
 }
+
+vlc_tick_t BasePeriod::getPeriodDuration() const
+{
+    return duration.Get();
+}
index b57a75d..814b41d 100644 (file)
@@ -46,6 +46,7 @@ namespace adaptive
                 void                                debug               (vlc_object_t *,int = 0) const;
 
                 virtual vlc_tick_t getPeriodStart() const; /* reimpl */
+                virtual vlc_tick_t getPeriodDuration() const;
                 virtual AbstractPlaylist *getPlaylist() const; /* reimpl */
 
                 Property<vlc_tick_t> duration;
index ad82fa5..27a4336 100644 (file)
@@ -258,6 +258,25 @@ ISegment * SegmentInformation::getNextSegment(SegmentInfoType type, uint64_t i_p
                 }
                 else
                 {
+                    /* check template upper bound */
+                    if(!getPlaylist()->isLive())
+                    {
+                        const Timescale timescale = templ->inheritTimescale();
+                        const stime_t segmentduration = templ->inheritDuration();
+                        vlc_tick_t totalduration = getPeriodDuration();
+                        if(totalduration == 0)
+                            totalduration = getPlaylist()->duration.Get();
+                        if(totalduration && segmentduration)
+                        {
+                            uint64_t endnum = templ->inheritStartNumber() +
+                                    (timescale.ToScaled(totalduration) + segmentduration - 1) / segmentduration;
+                            if(i_pos >= endnum)
+                            {
+                                *pi_newpos = i_pos;
+                                return NULL;
+                            }
+                        }
+                    }
                     *pi_newpos = i_pos;
                     /* start number */
                     *pi_newpos = std::max(templ->inheritStartNumber(), i_pos);
@@ -517,6 +536,14 @@ vlc_tick_t SegmentInformation::getPeriodStart() const
         return 0;
 }
 
+vlc_tick_t SegmentInformation::getPeriodDuration() const
+{
+    if(parent)
+        return parent->getPeriodDuration();
+    else
+        return 0;
+}
+
 void SegmentInformation::updateSegmentList(SegmentList *list, bool restamp)
 {
     if(segmentList && restamp)
index 48d6e9c..7b763eb 100644 (file)
@@ -52,6 +52,7 @@ namespace adaptive
                 virtual ~SegmentInformation();
 
                 virtual vlc_tick_t getPeriodStart() const;
+                virtual vlc_tick_t getPeriodDuration() const;
                 virtual AbstractPlaylist *getPlaylist() const;
 
                 class SplitPoint