[vlc-commits] demux: hls: fix reading file extension from uri

Francois Cartegnie git at videolan.org
Mon Jul 25 21:32:23 CEST 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Jul 25 21:31:16 2016 +0200| [e604a3a242c2b532d59b48846665c021240a5a22] | committer: Francois Cartegnie

demux: hls: fix reading file extension from uri

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

 modules/demux/adaptive/tools/Helper.cpp | 14 ++++++++++++++
 modules/demux/adaptive/tools/Helper.h   |  1 +
 modules/demux/hls/playlist/Parser.cpp   |  2 +-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/modules/demux/adaptive/tools/Helper.cpp b/modules/demux/adaptive/tools/Helper.cpp
index be5e122..9ad37fe 100644
--- a/modules/demux/adaptive/tools/Helper.cpp
+++ b/modules/demux/adaptive/tools/Helper.cpp
@@ -54,6 +54,20 @@ std::string Helper::getDirectoryPath    (const std::string &path)
     return (pos != std::string::npos) ? path.substr(0, pos) : path;
 }
 
+std::string Helper::getFileExtension (const std::string &uri)
+{
+    std::string extension;
+    std::size_t pos = uri.find_first_of("?#");
+    if(pos != std::string::npos)
+        extension = uri.substr(0, pos);
+    else
+        extension = uri;
+    pos = uri.find_last_of('.');
+    if(pos == std::string::npos)
+        return std::string();
+    return extension.substr(pos + 1);
+}
+
 bool Helper::ifind(std::string haystack, std::string needle)
 {
     transform(haystack.begin(), haystack.end(), haystack.begin(), toupper);
diff --git a/modules/demux/adaptive/tools/Helper.h b/modules/demux/adaptive/tools/Helper.h
index 8272887..4e58d63 100644
--- a/modules/demux/adaptive/tools/Helper.h
+++ b/modules/demux/adaptive/tools/Helper.h
@@ -35,6 +35,7 @@ namespace adaptive
         public:
             static std::string combinePaths     (const std::string &path1, const std::string &path2);
             static std::string getDirectoryPath (const std::string &path);
+            static std::string getFileExtension (const std::string &uri);
             static bool        ifind            (std::string haystack, std::string needle);
             static std::list<std::string> tokenize(const std::string &, char);
     };
diff --git a/modules/demux/hls/playlist/Parser.cpp b/modules/demux/hls/playlist/Parser.cpp
index 85267f3..f68ee1c 100644
--- a/modules/demux/hls/playlist/Parser.cpp
+++ b/modules/demux/hls/playlist/Parser.cpp
@@ -78,7 +78,7 @@ void M3U8Parser::setFormatFromExtension(Representation *rep, const std::string &
     std::size_t pos = filename.find_last_of('.');
     if(pos != std::string::npos)
     {
-        std::string extension = filename.substr(pos + 1);
+        std::string extension = Helper::getFileExtension(filename);
         transform(extension.begin(), extension.end(), extension.begin(), (int (*)(int))std::tolower);
         if(extension == "aac")
         {



More information about the vlc-commits mailing list