[vlc-commits] demux: hls: refactor parsing of encryption

Francois Cartegnie git at videolan.org
Mon Mar 30 16:16:15 CEST 2020


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Apr 19 11:34:24 2019 +0200| [7311aa7755ad157b184d22dded400fea6d32861a] | committer: Francois Cartegnie

demux: hls: refactor parsing of encryption

(cherry picked from commit 17b33eea06c3604ed06613ba35b2a713a52a5652)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=7311aa7755ad157b184d22dded400fea6d32861a
---

 modules/demux/hls/playlist/Parser.cpp | 68 +++++++++++++++++++----------------
 1 file changed, 37 insertions(+), 31 deletions(-)

diff --git a/modules/demux/hls/playlist/Parser.cpp b/modules/demux/hls/playlist/Parser.cpp
index d293d16805..a107dfd6d9 100644
--- a/modules/demux/hls/playlist/Parser.cpp
+++ b/modules/demux/hls/playlist/Parser.cpp
@@ -163,6 +163,41 @@ bool M3U8Parser::appendSegmentsFromPlaylistURI(vlc_object_t *p_obj, Representati
     return false;
 }
 
+static bool parseEncryption(const AttributesTag *keytag, const Url &playlistUrl,
+                            CommonEncryption &encryption)
+{
+    if( keytag->getAttributeByName("METHOD") &&
+        keytag->getAttributeByName("METHOD")->value == "AES-128" &&
+        keytag->getAttributeByName("URI") )
+    {
+        encryption.method = CommonEncryption::Method::AES_128;
+        encryption.uri.clear();
+
+        Url keyurl(keytag->getAttributeByName("URI")->quotedString());
+        if(!keyurl.hasScheme())
+        {
+            keyurl.prepend(Helper::getDirectoryPath(playlistUrl.toString()).append("/"));
+        }
+
+        encryption.uri = keyurl.toString();
+
+        if(keytag->getAttributeByName("IV"))
+        {
+            encryption.iv.clear();
+            encryption.iv = keytag->getAttributeByName("IV")->hexSequence();
+        }
+        return true;
+    }
+    else
+    {
+        /* unsupported or invalid */
+        encryption.method = CommonEncryption::Method::NONE;
+        encryption.uri.clear();
+        encryption.iv.clear();
+        return false;
+    }
+}
+
 void M3U8Parser::parseSegments(vlc_object_t *, Representation *rep, const std::list<Tag *> &tagslist)
 {
     SegmentList *segmentList = new (std::nothrow) SegmentList(rep);
@@ -277,37 +312,8 @@ void M3U8Parser::parseSegments(vlc_object_t *, Representation *rep, const std::l
                 break;
 
             case AttributesTag::EXTXKEY:
-            {
-                const AttributesTag *keytag = static_cast<const AttributesTag *>(tag);
-                if( keytag->getAttributeByName("METHOD") &&
-                    keytag->getAttributeByName("METHOD")->value == "AES-128" &&
-                    keytag->getAttributeByName("URI") )
-                {
-                    encryption.method = CommonEncryption::Method::AES_128;
-                    encryption.uri.clear();
-
-                    Url keyurl(keytag->getAttributeByName("URI")->quotedString());
-                    if(!keyurl.hasScheme())
-                    {
-                        keyurl.prepend(Helper::getDirectoryPath(rep->getPlaylistUrl().toString()).append("/"));
-                    }
-
-                    encryption.uri = keyurl.toString();
-
-                    if(keytag->getAttributeByName("IV"))
-                    {
-                        encryption.iv.clear();
-                        encryption.iv = keytag->getAttributeByName("IV")->hexSequence();
-                    }
-                }
-                else
-                {
-                    /* unsupported or invalid */
-                    encryption.method = CommonEncryption::Method::NONE;
-                    encryption.uri.clear();
-                    encryption.iv.clear();
-                }
-            }
+                parseEncryption(static_cast<const AttributesTag *>(tag),
+                                rep->getPlaylistUrl(), encryption);
             break;
 
             case AttributesTag::EXTXMAP:



More information about the vlc-commits mailing list