]> git.sesse.net Git - vlc/commitdiff
demux: dash: factorize timescales inheritance
authorFrancois Cartegnie <fcvlcdev@free.fr>
Mon, 12 Jan 2015 11:45:04 +0000 (12:45 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Mon, 12 Jan 2015 19:21:57 +0000 (20:21 +0100)
modules/demux/dash/mpd/SegmentInfoCommon.cpp
modules/demux/dash/mpd/SegmentInfoCommon.h
modules/demux/dash/mpd/SegmentInformation.cpp
modules/demux/dash/mpd/SegmentInformation.hpp
modules/demux/dash/mpd/SegmentList.cpp
modules/demux/dash/mpd/SegmentList.h
modules/demux/dash/mpd/SegmentTemplate.cpp
modules/demux/dash/mpd/SegmentTemplate.h
modules/demux/dash/mpd/Url.cpp

index eebacac23d8e371d3f2ef9d96f5b91efd05d3753..7d5036051bb278322f2cb340db056aee702c0b60 100644 (file)
@@ -43,6 +43,26 @@ Timelineable::~Timelineable()
     delete segmentTimeline.Get();
 }
 
+TimescaleAble::TimescaleAble(TimescaleAble *parent)
+{
+    timescale.Set(0);
+    parentTimescale = parent;
+}
+
+TimescaleAble::~TimescaleAble()
+{
+}
+
+uint64_t TimescaleAble::inheritTimescale() const
+{
+    if(timescale.Get())
+        return timescale.Get();
+    else if(parentTimescale)
+        return parentTimescale->inheritTimescale();
+    else
+        return 1;
+}
+
 SegmentInfoCommon::SegmentInfoCommon( ICanonicalUrl *parent ) :
     ICanonicalUrl( parent ), Initializable(),
     duration( 0 ),
index 9c37aed28e6ae4da6a21ab070f6d530ef1aa7621..c4b9bcc533675fd59666dd9a22fbafc448c36cff 100644 (file)
@@ -60,6 +60,18 @@ namespace dash
                 Property<SegmentTimeline *> segmentTimeline;
         };
 
+        class TimescaleAble
+        {
+            public:
+                TimescaleAble( TimescaleAble * = NULL );
+                ~TimescaleAble();
+                uint64_t inheritTimescale() const;
+                Property<uint64_t> timescale;
+
+            private:
+                TimescaleAble *parentTimescale;
+        };
+
         template<class T> class UniqueNess
         {
             public:
index 680b1afe3bab5631b63c0f0446254d466e7e6830..4a8c46199456db65d507aa14b58313e6aa2846dc 100644 (file)
 #include "SegmentList.h"
 #include "SegmentTemplate.h"
 #include "SegmentTimeline.h"
+#include "MPD.h"
 
 using namespace dash::mpd;
 using namespace std;
 
 SegmentInformation::SegmentInformation(SegmentInformation *parent_) :
-    ICanonicalUrl( parent_ )
+    ICanonicalUrl( parent_ ),
+    TimescaleAble( parent_ )
 {
     parent = parent_;
-    segmentBase = NULL;
-    segmentList = NULL;
-    mediaSegmentTemplate = NULL;
-    bitswitch_policy = BITSWITCH_INHERIT;
-    timescale.Set(0);
+    init();
 }
 
-SegmentInformation::SegmentInformation(ICanonicalUrl * parent_) :
-    ICanonicalUrl( parent_ )
+SegmentInformation::SegmentInformation(MPD * parent_) :
+    ICanonicalUrl(parent_),
+    TimescaleAble()
 {
     parent = NULL;
+    init();
+}
+
+void SegmentInformation::init()
+{
     segmentBase = NULL;
     segmentList = NULL;
     mediaSegmentTemplate = NULL;
     bitswitch_policy = BITSWITCH_INHERIT;
-    timescale.Set(0);
 }
 
 SegmentInformation::~SegmentInformation()
@@ -159,24 +162,22 @@ bool SegmentInformation::getSegmentNumberByTime(mtime_t time, uint64_t *ret) con
 {
     SegmentList *segList;
     MediaSegmentTemplate *mediaTemplate;
-    uint64_t timescale = 0;
+    uint64_t timescale = 1;
     mtime_t duration = 0;
 
     if( (mediaTemplate = inheritSegmentTemplate()) )
     {
-        timescale = mediaTemplate->timescale.Get();
+        timescale = mediaTemplate->inheritTimescale();
         duration = mediaTemplate->duration.Get();
     }
     else if ( (segList = inheritSegmentList()) )
     {
-        timescale = segList->timescale.Get();
+        timescale = segList->inheritTimescale();
         duration = segList->getDuration();
     }
 
     if(duration)
     {
-        if(!timescale)
-            timescale = getTimescale(); /* inherit */
         *ret = time / (CLOCK_FREQ * duration / timescale);
         return true;
     }
@@ -188,11 +189,11 @@ mtime_t SegmentInformation::getPlaybackTimeBySegmentNumber(uint64_t number) cons
 {
     SegmentList *segList;
     MediaSegmentTemplate *mediaTemplate;
-    uint64_t timescale = 0;
+    uint64_t timescale = 1;
     mtime_t time = 0;
     if( (mediaTemplate = inheritSegmentTemplate()) )
     {
-        timescale = mediaTemplate->timescale.Get();
+        timescale = mediaTemplate->inheritTimescale();
         if(mediaTemplate->segmentTimeline.Get())
         {
             time = mediaTemplate->segmentTimeline.Get()->
@@ -205,16 +206,12 @@ mtime_t SegmentInformation::getPlaybackTimeBySegmentNumber(uint64_t number) cons
     }
     else if ( (segList = inheritSegmentList()) )
     {
-        timescale = segList->timescale.Get();
+        timescale = segList->inheritTimescale();
         time = number * segList->getDuration();
     }
 
     if(time)
-    {
-        if(!timescale)
-            timescale = getTimescale(); /* inherit */
         time = CLOCK_FREQ * time / timescale;
-    }
 
     return time;
 }
@@ -237,16 +234,6 @@ bool SegmentInformation::canBitswitch() const
         return (bitswitch_policy == BITSWITCH_YES);
 }
 
-uint64_t SegmentInformation::getTimescale() const
-{
-    if (timescale.Get())
-        return timescale.Get();
-    else if (parent)
-        return parent->getTimescale();
-    else
-        return 1;
-}
-
 mtime_t SegmentInformation::getPeriodStart() const
 {
     if(parent)
index ef0de5ba78928ff42a10cb58a54b504bddb11f23..a4164e0a73d04d96fb33b05167cd21b243b92157 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "ICanonicalUrl.hpp"
 #include "Properties.hpp"
+#include "SegmentInfoCommon.h"
 #include <vlc_common.h>
 #include <vector>
 
@@ -40,19 +41,20 @@ namespace dash
         class SegmentList;
         class SegmentTemplate;
         class SegmentTimeline;
+        class MPD;
 
         /* common segment elements for period/adaptset/rep 5.3.9.1,
          * with properties inheritance */
-        class SegmentInformation : public ICanonicalUrl
+        class SegmentInformation : public ICanonicalUrl,
+                                   public TimescaleAble
         {
             friend class IsoffMainParser;
 
             public:
                 SegmentInformation( SegmentInformation * = 0 );
-                explicit SegmentInformation( ICanonicalUrl * );
+                explicit SegmentInformation( MPD * );
                 virtual ~SegmentInformation();
                 bool canBitswitch() const;
-                uint64_t getTimescale() const;
                 virtual mtime_t getPeriodStart() const;
 
                 class SplitPoint
@@ -82,6 +84,7 @@ namespace dash
                 std::vector<SegmentInformation *> childs;
 
             private:
+                void init();
                 void setSegmentList(SegmentList *);
                 void setSegmentBase(SegmentBase *);
                 void setSegmentTemplate(MediaSegmentTemplate *);
@@ -102,8 +105,6 @@ namespace dash
                     BITSWITCH_YES,
                     BITSWITCH_NO
                 } bitswitch_policy;
-
-                Property<uint64_t> timescale;
         };
     }
 }
index 87c7bcd72149a6eace1bd3f043818d54eea39a03..a0f91839599b0d5cc04bded9d5cc573c6fae318f 100644 (file)
 
 #include "SegmentList.h"
 #include "Segment.h"
+#include "SegmentInformation.hpp"
 
 using namespace dash::mpd;
 
-SegmentList::SegmentList( ICanonicalUrl *parent ):
-    SegmentInfoCommon( parent )
+SegmentList::SegmentList( SegmentInformation *parent ):
+    SegmentInfoCommon( parent ), TimescaleAble( parent )
 {
-    timescale.Set(0);
 }
 SegmentList::~SegmentList()
 {
index 8e685e0c1dfa6106b1b9e702a8ae63862026d2e3..58750f3175b9d152288c8dccf06d5c1b304f3dd6 100644 (file)
@@ -39,17 +39,18 @@ namespace dash
 {
     namespace mpd
     {
-        class SegmentList : public SegmentInfoCommon
+        class SegmentInformation;
+
+        class SegmentList : public SegmentInfoCommon,
+                            public TimescaleAble
         {
             public:
-                SegmentList             ( ICanonicalUrl * = NULL );
+                SegmentList             ( SegmentInformation * = NULL );
                 virtual ~SegmentList    ();
 
                 const std::vector<Segment *>&   getSegments() const;
                 void                    addSegment(Segment *seg);
 
-                Property<uint64_t> timescale;
-
             private:
                 std::vector<Segment *>  segments;
         };
index b9e8c3fb3aaade2ee40a6fd614b5a52579ff874d..fae83d44a4fa483cbd69c58be392d787504b51ed 100644 (file)
@@ -49,12 +49,11 @@ Url BaseSegmentTemplate::getUrlSegment() const
     return ret;
 }
 
-MediaSegmentTemplate::MediaSegmentTemplate( ICanonicalUrl *parent ) :
-    BaseSegmentTemplate( parent ), Timelineable()
+MediaSegmentTemplate::MediaSegmentTemplate( SegmentInformation *parent ) :
+    BaseSegmentTemplate( parent ), Timelineable(), TimescaleAble( parent )
 {
     debugName = "SegmentTemplate";
     classId = Segment::CLASSID_SEGMENT;
-    timescale.Set( 0 );
     startNumber.Set( 0 );
     initialisationSegment.Set( NULL );
 }
index df827f26620b25f5adcf1b06eaf4c4bd17df244a..5644e016cf42e68354e073c8c77a81499dc73347 100644 (file)
@@ -44,12 +44,12 @@ namespace dash
 
         class MediaSegmentTemplate : public BaseSegmentTemplate,
                                      public Initializable<InitSegmentTemplate>,
-                                     public Timelineable
+                                     public Timelineable,
+                                     public TimescaleAble
         {
             public:
-                MediaSegmentTemplate( ICanonicalUrl * = NULL );
+                MediaSegmentTemplate( SegmentInformation * = NULL );
                 Property<size_t>        startNumber;
-                Property<uint64_t>      timescale;
         };
 
         class InitSegmentTemplate : public BaseSegmentTemplate
index 466abe6ac9ce1cb8e22307c6067b4c49d99dca8e..46c4ab6a719a3d45d5f280e717a768ee39ab324a 100644 (file)
@@ -116,9 +116,7 @@ size_t Url::Component::getSegmentNumber(size_t index, const Representation *rep)
             mtime_t streamstart = rep->getMPD()->availabilityStartTime.Get();
             streamstart += rep->getPeriodStart();
             mtime_t duration = templ->duration.Get();
-            uint64_t timescale = templ->timescale.Get() ?
-                                 templ->timescale.Get() :
-                                 rep->getTimescale();
+            uint64_t timescale = templ->inheritTimescale();
             if(duration && timescale)
                 index += (playbackstart - streamstart) * timescale / duration;
         }