[vlc-commits] demux: adaptative: add sequence number to all segments

Francois Cartegnie git at videolan.org
Tue Sep 22 00:38:51 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Sep 17 19:49:52 2015 +0200| [458dc05cd98ab84b69cce95237388f60ff8156f4] | committer: Francois Cartegnie

demux: adaptative: add sequence number to all segments

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

 modules/demux/adaptative/playlist/Segment.cpp |   14 ++++++++++++++
 modules/demux/adaptative/playlist/Segment.h   |    5 +++++
 modules/demux/hls/playlist/HLSSegment.cpp     |   16 ++++++++--------
 modules/demux/hls/playlist/HLSSegment.hpp     |    1 -
 4 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/modules/demux/adaptative/playlist/Segment.cpp b/modules/demux/adaptative/playlist/Segment.cpp
index d707aef..57fde30 100644
--- a/modules/demux/adaptative/playlist/Segment.cpp
+++ b/modules/demux/adaptative/playlist/Segment.cpp
@@ -34,6 +34,9 @@
 using namespace adaptative::http;
 using namespace adaptative::playlist;
 
+const int ISegment::SEQUENCE_INVALID = 0;
+const int ISegment::SEQUENCE_FIRST   = 1;
+
 ISegment::ISegment(const ICanonicalUrl *parent):
     ICanonicalUrl( parent ),
     startByte  (0),
@@ -44,6 +47,7 @@ ISegment::ISegment(const ICanonicalUrl *parent):
     startTime.Set(0);
     duration.Set(0);
     chunksuse.Set(0);
+    sequence = SEQUENCE_INVALID;
 }
 
 ISegment::~ISegment()
@@ -92,6 +96,16 @@ void ISegment::setByteRange(size_t start, size_t end)
     endByte   = end;
 }
 
+void ISegment::setSequenceNumber(uint64_t seq)
+{
+    sequence = SEQUENCE_FIRST + seq;
+}
+
+uint64_t ISegment::getSequenceNumber() const
+{
+    return sequence;
+}
+
 size_t ISegment::getOffset() const
 {
     return startByte;
diff --git a/modules/demux/adaptative/playlist/Segment.h b/modules/demux/adaptative/playlist/Segment.h
index 3c124d4..2b0e1f6 100644
--- a/modules/demux/adaptative/playlist/Segment.h
+++ b/modules/demux/adaptative/playlist/Segment.h
@@ -55,6 +55,8 @@ namespace adaptative
                  */
                 virtual SegmentChunk*                   toChunk         (size_t, BaseRepresentation * = NULL);
                 virtual void                            setByteRange    (size_t start, size_t end);
+                virtual void                            setSequenceNumber(uint64_t);
+                virtual uint64_t                        getSequenceNumber() const;
                 virtual size_t                          getOffset       () const;
                 virtual std::vector<ISegment*>          subSegments     () = 0;
                 virtual void                            addSubSegment   (SubSegment *) = 0;
@@ -75,6 +77,9 @@ namespace adaptative
                 size_t                  endByte;
                 std::string             debugName;
                 int                     classId;
+                uint64_t                sequence;
+                static const int        SEQUENCE_INVALID;
+                static const int        SEQUENCE_FIRST;
 
                 virtual SegmentChunk * getChunk(const std::string &);
         };
diff --git a/modules/demux/hls/playlist/HLSSegment.cpp b/modules/demux/hls/playlist/HLSSegment.cpp
index 7cac08e..4fb4b0f 100644
--- a/modules/demux/hls/playlist/HLSSegment.cpp
+++ b/modules/demux/hls/playlist/HLSSegment.cpp
@@ -38,7 +38,7 @@ SegmentEncryption::SegmentEncryption()
 HLSSegment::HLSSegment( ICanonicalUrl *parent, uint64_t seq ) :
     Segment( parent )
 {
-    sequence = seq;
+    setSequenceNumber(seq);
 #ifdef HAVE_GCRYPT
     ctx = NULL;
 #endif
@@ -85,10 +85,10 @@ void HLSSegment::onChunkDownload(block_t **pp_block, SegmentChunk *chunk, BaseRe
             {
                 encryption.iv.clear();
                 encryption.iv.resize(16);
-                encryption.iv[15] = sequence & 0xff;
-                encryption.iv[14] = (sequence >> 8)& 0xff;
-                encryption.iv[13] = (sequence >> 16)& 0xff;
-                encryption.iv[12] = (sequence >> 24)& 0xff;
+                encryption.iv[15] = (getSequenceNumber() - Segment::SEQUENCE_FIRST) & 0xff;
+                encryption.iv[14] = ((getSequenceNumber() - Segment::SEQUENCE_FIRST) >> 8)& 0xff;
+                encryption.iv[13] = ((getSequenceNumber() - Segment::SEQUENCE_FIRST) >> 16)& 0xff;
+                encryption.iv[12] = ((getSequenceNumber() - Segment::SEQUENCE_FIRST) >> 24)& 0xff;
             }
 
             if( gcry_cipher_open(&ctx, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0) ||
@@ -148,7 +148,7 @@ void HLSSegment::debug(vlc_object_t *obj, int indent) const
 {
     std::stringstream ss;
     ss << std::string(indent, ' ') << debugName <<
-    " #" << sequence <<
+    " #" << (getSequenceNumber() - Segment::SEQUENCE_FIRST) <<
     " url=" << getUrlSegment().toString();
     if(startByte!=endByte)
         ss << " @" << startByte << ".." << endByte;
@@ -160,9 +160,9 @@ int HLSSegment::compare(ISegment *segment) const
     HLSSegment *hlssegment = dynamic_cast<HLSSegment *>(segment);
     if(hlssegment)
     {
-        if (sequence > hlssegment->sequence)
+        if (getSequenceNumber() > hlssegment->getSequenceNumber())
             return 1;
-        else if(sequence < hlssegment->sequence)
+        else if(getSequenceNumber() < hlssegment->getSequenceNumber())
             return -1;
         else
             return 0;
diff --git a/modules/demux/hls/playlist/HLSSegment.hpp b/modules/demux/hls/playlist/HLSSegment.hpp
index 848ab03..37e5ca0 100644
--- a/modules/demux/hls/playlist/HLSSegment.hpp
+++ b/modules/demux/hls/playlist/HLSSegment.hpp
@@ -63,7 +63,6 @@ namespace hls
                 virtual void onChunkDownload(block_t **, SegmentChunk *, BaseRepresentation *); /* reimpl */
                 void checkFormat(block_t *, SegmentChunk *, BaseRepresentation *);
 
-                uint64_t sequence;
                 SegmentEncryption encryption;
 #ifdef HAVE_GCRYPT
                 gcry_cipher_hd_t ctx;



More information about the vlc-commits mailing list