[vlc-commits] demux: adaptive: add encryption to segment info

Francois Cartegnie git at videolan.org
Fri May 10 11:13:28 CEST 2019


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Apr 19 13:25:19 2019 +0200| [29d5f44edf21e31e13c5469e8199c728caec8c56] | committer: Francois Cartegnie

demux: adaptive: add encryption to segment info

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

 modules/demux/adaptive/encryption/CommonEncryption.cpp | 11 +++++++++++
 modules/demux/adaptive/encryption/CommonEncryption.hpp |  1 +
 modules/demux/adaptive/playlist/Segment.cpp            |  9 ++++++---
 modules/demux/adaptive/playlist/SegmentInformation.cpp | 13 +++++++++++++
 modules/demux/adaptive/playlist/SegmentInformation.hpp |  4 ++++
 5 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/modules/demux/adaptive/encryption/CommonEncryption.cpp b/modules/demux/adaptive/encryption/CommonEncryption.cpp
index 743e04e860..990016d2c7 100644
--- a/modules/demux/adaptive/encryption/CommonEncryption.cpp
+++ b/modules/demux/adaptive/encryption/CommonEncryption.cpp
@@ -41,6 +41,17 @@ CommonEncryption::CommonEncryption()
     method = CommonEncryption::Method::NONE;
 }
 
+void CommonEncryption::mergeWith(const CommonEncryption &other)
+{
+    if(method == CommonEncryption::Method::NONE &&
+       other.method != CommonEncryption::Method::NONE)
+        method = other.method;
+    if(uri.empty() && !other.uri.empty())
+        uri = other.uri;
+    if(iv.empty() && !other.iv.empty())
+        iv = other.iv;
+}
+
 CommonEncryptionSession::CommonEncryptionSession()
 {
     ctx = NULL;
diff --git a/modules/demux/adaptive/encryption/CommonEncryption.hpp b/modules/demux/adaptive/encryption/CommonEncryption.hpp
index 66631c3d2a..1645c57e94 100644
--- a/modules/demux/adaptive/encryption/CommonEncryption.hpp
+++ b/modules/demux/adaptive/encryption/CommonEncryption.hpp
@@ -33,6 +33,7 @@ namespace adaptive
         {
             public:
                 CommonEncryption();
+                void mergeWith(const CommonEncryption &);
                 enum Method
                 {
                     NONE,
diff --git a/modules/demux/adaptive/playlist/Segment.cpp b/modules/demux/adaptive/playlist/Segment.cpp
index 36051a9450..21b0707286 100644
--- a/modules/demux/adaptive/playlist/Segment.cpp
+++ b/modules/demux/adaptive/playlist/Segment.cpp
@@ -67,12 +67,15 @@ void ISegment::onChunkDownload(block_t **, SegmentChunk *, BaseRepresentation *)
 
 }
 
-bool ISegment::prepareChunk(SharedResources *res, SegmentChunk *chunk, BaseRepresentation *)
+bool ISegment::prepareChunk(SharedResources *res, SegmentChunk *chunk, BaseRepresentation *rep)
 {
-    if(encryption.method != CommonEncryption::Method::NONE)
+    CommonEncryption enc = encryption;
+    enc.mergeWith(rep->intheritEncryption());
+
+    if(enc.method != CommonEncryption::Method::NONE)
     {
         CommonEncryptionSession *encryptionSession = new CommonEncryptionSession();
-        if(!encryptionSession->start(res, encryption))
+        if(!encryptionSession->start(res, enc))
         {
             delete encryptionSession;
             return false;
diff --git a/modules/demux/adaptive/playlist/SegmentInformation.cpp b/modules/demux/adaptive/playlist/SegmentInformation.cpp
index ba5e4e30c7..d39a55ee49 100644
--- a/modules/demux/adaptive/playlist/SegmentInformation.cpp
+++ b/modules/demux/adaptive/playlist/SegmentInformation.cpp
@@ -30,6 +30,7 @@
 #include "SegmentTimeline.h"
 #include "AbstractPlaylist.hpp"
 #include "BaseRepresentation.h"
+#include "../encryption/CommonEncryption.hpp"
 
 #include <algorithm>
 #include <cassert>
@@ -510,6 +511,18 @@ uint64_t SegmentInformation::translateSegmentNumber(uint64_t num, const SegmentI
     return num;
 }
 
+const CommonEncryption & SegmentInformation::intheritEncryption() const
+{
+    if(parent && commonEncryption.method == CommonEncryption::Method::NONE)
+        return parent->intheritEncryption();
+    return commonEncryption;
+}
+
+void SegmentInformation::setEncryption(const CommonEncryption &enc)
+{
+    commonEncryption = enc;
+}
+
 vlc_tick_t SegmentInformation::getPeriodStart() const
 {
     if(parent)
diff --git a/modules/demux/adaptive/playlist/SegmentInformation.hpp b/modules/demux/adaptive/playlist/SegmentInformation.hpp
index 0307d90985..5eb12183b5 100644
--- a/modules/demux/adaptive/playlist/SegmentInformation.hpp
+++ b/modules/demux/adaptive/playlist/SegmentInformation.hpp
@@ -22,6 +22,7 @@
 
 #include "ICanonicalUrl.hpp"
 #include "../tools/Properties.hpp"
+#include "../encryption/CommonEncryption.hpp"
 #include "SegmentInfoCommon.h"
 #include <vlc_common.h>
 #include <vector>
@@ -86,6 +87,8 @@ namespace adaptive
                 virtual void pruneBySegmentNumber(uint64_t);
                 virtual void pruneByPlaybackTime(vlc_tick_t);
                 virtual uint64_t translateSegmentNumber(uint64_t, const SegmentInformation *) const;
+                void setEncryption(const CommonEncryption &);
+                const CommonEncryption & intheritEncryption() const;
 
             protected:
                 std::size_t getAllSegments(std::vector<ISegment *> &) const;
@@ -110,6 +113,7 @@ namespace adaptive
                 SegmentBase     *segmentBase;
                 SegmentList     *segmentList;
                 MediaSegmentTemplate *mediaSegmentTemplate;
+                CommonEncryption commonEncryption;
         };
     }
 }



More information about the vlc-commits mailing list