[vlc-commits] demux: dash: fix TimeLine class

Francois Cartegnie git at videolan.org
Mon Jan 12 20:22:06 CET 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Jan  7 02:25:29 2015 +0100| [19eaa9542add910bdd9fb1f2efb8870e1027eff2] | committer: Francois Cartegnie

demux: dash: fix TimeLine class

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=19eaa9542add910bdd9fb1f2efb8870e1027eff2
---

 modules/demux/dash/mpd/SegmentInfoCommon.cpp |   25 +++++-----
 modules/demux/dash/mpd/SegmentInfoCommon.h   |   11 +++--
 modules/demux/dash/mpd/SegmentTemplate.cpp   |    2 +-
 modules/demux/dash/mpd/SegmentTemplate.h     |    3 +-
 modules/demux/dash/mpd/SegmentTimeline.cpp   |   67 +++++---------------------
 modules/demux/dash/mpd/SegmentTimeline.h     |   32 ++++++------
 6 files changed, 49 insertions(+), 91 deletions(-)

diff --git a/modules/demux/dash/mpd/SegmentInfoCommon.cpp b/modules/demux/dash/mpd/SegmentInfoCommon.cpp
index 69d2129..c0d342d 100644
--- a/modules/demux/dash/mpd/SegmentInfoCommon.cpp
+++ b/modules/demux/dash/mpd/SegmentInfoCommon.cpp
@@ -33,17 +33,25 @@
 
 using namespace dash::mpd;
 
+Timelineable::Timelineable()
+{
+    segmentTimeline.Set(NULL);
+}
+
+Timelineable::~Timelineable()
+{
+    delete segmentTimeline.Get();
+}
+
 SegmentInfoCommon::SegmentInfoCommon( ICanonicalUrl *parent ) :
     ICanonicalUrl( parent ), Initializable(),
     duration( -1 ),
-    startIndex( 0 ),
-    segmentTimeline( NULL )
+    startIndex( 0 )
 {
 }
 
 SegmentInfoCommon::~SegmentInfoCommon()
 {
-    delete this->segmentTimeline;
 }
 
 time_t      SegmentInfoCommon::getDuration() const
@@ -73,17 +81,6 @@ void SegmentInfoCommon::appendBaseURL(const std::string &url)
     this->baseURLs.push_back( url );
 }
 
-const SegmentTimeline *SegmentInfoCommon::getSegmentTimeline() const
-{
-    return this->segmentTimeline;
-}
-
-void SegmentInfoCommon::setSegmentTimeline( const SegmentTimeline *segTl )
-{
-    if ( segTl != NULL )
-        this->segmentTimeline = segTl;
-}
-
 Url SegmentInfoCommon::getUrlSegment() const
 {
     Url ret = getParentUrlSegment();
diff --git a/modules/demux/dash/mpd/SegmentInfoCommon.h b/modules/demux/dash/mpd/SegmentInfoCommon.h
index a620a98..742940f 100644
--- a/modules/demux/dash/mpd/SegmentInfoCommon.h
+++ b/modules/demux/dash/mpd/SegmentInfoCommon.h
@@ -52,6 +52,14 @@ namespace dash
                 Property<T *> initialisationSegment;
         };
 
+        class Timelineable
+        {
+            public:
+                Timelineable();
+                ~Timelineable();
+                Property<SegmentTimeline *> segmentTimeline;
+        };
+
         class SegmentInfoCommon : public ICanonicalUrl,
                                   public Initializable<Segment>
         {
@@ -63,15 +71,12 @@ namespace dash
                 int                     getStartIndex() const;
                 void                    setStartIndex( int startIndex );
                 void                    appendBaseURL( const std::string& url );
-                const SegmentTimeline*  getSegmentTimeline() const;
-                void                    setSegmentTimeline( const SegmentTimeline *segTl );
                 virtual Url             getUrlSegment() const; /* impl */
 
             private:
                 time_t                  duration;
                 int                     startIndex;
                 std::list<std::string>  baseURLs;
-                const SegmentTimeline*  segmentTimeline;
         };
     }
 }
diff --git a/modules/demux/dash/mpd/SegmentTemplate.cpp b/modules/demux/dash/mpd/SegmentTemplate.cpp
index f3e0397..74cddae 100644
--- a/modules/demux/dash/mpd/SegmentTemplate.cpp
+++ b/modules/demux/dash/mpd/SegmentTemplate.cpp
@@ -50,7 +50,7 @@ Url BaseSegmentTemplate::getUrlSegment() const
 }
 
 MediaSegmentTemplate::MediaSegmentTemplate( ICanonicalUrl *parent ) :
-    BaseSegmentTemplate( parent )
+    BaseSegmentTemplate( parent ), Timelineable()
 {
     debugName = "SegmentTemplate";
     classId = Segment::CLASSID_SEGMENT;
diff --git a/modules/demux/dash/mpd/SegmentTemplate.h b/modules/demux/dash/mpd/SegmentTemplate.h
index 0730fa0..f3aefdf 100644
--- a/modules/demux/dash/mpd/SegmentTemplate.h
+++ b/modules/demux/dash/mpd/SegmentTemplate.h
@@ -43,7 +43,8 @@ namespace dash
         };
 
         class MediaSegmentTemplate : public BaseSegmentTemplate,
-                                     public Initializable<InitSegmentTemplate>
+                                     public Initializable<InitSegmentTemplate>,
+                                     public Timelineable
         {
             public:
                 MediaSegmentTemplate( ICanonicalUrl * = NULL );
diff --git a/modules/demux/dash/mpd/SegmentTimeline.cpp b/modules/demux/dash/mpd/SegmentTimeline.cpp
index d6dcc38..2f1b240 100644
--- a/modules/demux/dash/mpd/SegmentTimeline.cpp
+++ b/modules/demux/dash/mpd/SegmentTimeline.cpp
@@ -27,72 +27,29 @@
 
 #include "SegmentTimeline.h"
 
-#include <vlc_common.h>
-#include <vlc_arrays.h>
-
-#include <iostream>
-
 using namespace dash::mpd;
 
-SegmentTimeline::SegmentTimeline() :
-    timescale( -1 )
+SegmentTimeline::SegmentTimeline()
 {
 }
 
 SegmentTimeline::~SegmentTimeline()
 {
-    vlc_delete_all( this->elements );
-}
-
-int dash::mpd::SegmentTimeline::getTimescale() const
-{
-    return this->timescale;
-}
-
-void dash::mpd::SegmentTimeline::setTimescale(int timescale)
-{
-    this->timescale = timescale;
-}
-
-void dash::mpd::SegmentTimeline::addElement(dash::mpd::SegmentTimeline::Element *e)
-{
-    int64_t offset = 0;
-
-    for ( int i = 0; i < e->r; ++i )
-    {
-        this->elements.push_back( e );
-        e = new SegmentTimeline::Element( *e );
-        offset += e->d;
-        e->t += offset;
-    }
-    this->elements.push_back( e );
-}
-
-const SegmentTimeline::Element*    SegmentTimeline::getElement( unsigned int index ) const
-{
-    if ( this->elements.size() <= index )
-        return NULL;
-    std::list<Element*>::const_iterator     it = this->elements.begin();
-    std::list<Element*>::const_iterator     end = this->elements.end();
-    unsigned int                            i = 0;
-    while ( it != end )
-    {
-        if ( i == index )
-            return *it;
-        ++it;
-        ++i;
-    }
-    return NULL;
+    std::list<Element *>::iterator it;
+    for(it = elements.begin(); it != elements.end(); it++)
+        delete *it;
 }
 
-dash::mpd::SegmentTimeline::Element::Element() :
-    r( 0 )
+void SegmentTimeline::addElement(mtime_t d, uint64_t r, mtime_t t)
 {
+    Element *element = new (std::nothrow) Element(d, r, t);
+    if(element)
+        elements.push_back(element);
 }
 
-SegmentTimeline::Element::Element(const SegmentTimeline::Element &e) :
-    t( e.t ),
-    d( e.d ),
-    r( 0 )
+SegmentTimeline::Element::Element(mtime_t d_, uint64_t r_, mtime_t t_)
 {
+    d = d_;
+    t = t_;
+    r = r_;
 }
diff --git a/modules/demux/dash/mpd/SegmentTimeline.h b/modules/demux/dash/mpd/SegmentTimeline.h
index 7763bbe..9764730 100644
--- a/modules/demux/dash/mpd/SegmentTimeline.h
+++ b/modules/demux/dash/mpd/SegmentTimeline.h
@@ -24,9 +24,8 @@
 #ifndef SEGMENTTIMELINE_H
 #define SEGMENTTIMELINE_H
 
-#include <sys/types.h>
+#include <vlc_common.h>
 #include <list>
-#include <stdint.h>
 
 namespace dash
 {
@@ -34,25 +33,24 @@ namespace dash
     {
         class SegmentTimeline
         {
+            class Element;
+
             public:
-                struct  Element
-                {
-                    Element();
-                    Element( const Element& e );
-                    int64_t     t;
-                    int64_t     d;
-                    int         r;
-                };
                 SegmentTimeline();
-                ~SegmentTimeline();
-                int                     getTimescale() const;
-                void                    setTimescale( int timescale );
-                void                    addElement( Element* e );
-                const Element*          getElement( unsigned int index ) const;
+                virtual ~SegmentTimeline();
+                void addElement(mtime_t d, uint64_t r = 0, mtime_t t = 0);
 
             private:
-                int                     timescale;
-                std::list<Element*>     elements;
+                std::list<Element *> elements;
+
+                class Element
+                {
+                    public:
+                        Element(mtime_t, uint64_t, mtime_t);
+                        mtime_t  t;
+                        mtime_t  d;
+                        uint64_t r;
+                };
         };
     }
 }



More information about the vlc-commits mailing list