[vlc-commits] demux: adaptive: move mime to format conversion

Francois Cartegnie git at videolan.org
Mon Feb 26 12:14:31 CET 2018


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Feb 21 10:43:06 2018 +0100| [b4b58db68ff1d869ad2018738506608d93e6fa1e] | committer: Francois Cartegnie

demux: adaptive: move mime to format conversion

(cherry picked from commit 8f0953011bb2945f42ed3878cfe646a259601685)

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

 modules/demux/adaptive/StreamFormat.cpp     | 21 +++++++++++++++++++++
 modules/demux/adaptive/StreamFormat.hpp     |  1 +
 modules/demux/adaptive/plumbing/Demuxer.cpp |  1 +
 modules/demux/dash/mpd/AdaptationSet.cpp    |  2 +-
 modules/demux/dash/mpd/MPD.cpp              | 18 ------------------
 modules/demux/dash/mpd/MPD.h                |  2 --
 modules/demux/dash/mpd/Representation.cpp   |  4 ++--
 7 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/modules/demux/adaptive/StreamFormat.cpp b/modules/demux/adaptive/StreamFormat.cpp
index 27364dc7fd..11cee69dac 100644
--- a/modules/demux/adaptive/StreamFormat.cpp
+++ b/modules/demux/adaptive/StreamFormat.cpp
@@ -23,6 +23,7 @@
 #endif
 
 #include "StreamFormat.hpp"
+#include <algorithm>
 
 using namespace adaptive;
 
@@ -58,6 +59,26 @@ StreamFormat::StreamFormat( unsigned formatid_ )
     formatid = formatid_;
 }
 
+StreamFormat::StreamFormat( const std::string &mimetype )
+{
+    std::string mime = mimetype;
+    std::transform(mime.begin(), mime.end(), mime.begin(), ::tolower);
+    std::string::size_type pos = mime.find("/");
+    formatid = UNSUPPORTED;
+    if(pos != std::string::npos)
+    {
+        std::string tail = mime.substr(pos + 1);
+        if(tail == "mp4")
+            formatid = StreamFormat::MP4;
+        else if (tail == "mp2t")
+            formatid = StreamFormat::MPEG2TS;
+        else if (tail == "vtt")
+            formatid = StreamFormat::WEBVTT;
+        else if (tail == "ttml+xml")
+            formatid = StreamFormat::TTML;
+    }
+}
+
 StreamFormat::~StreamFormat()
 {
 
diff --git a/modules/demux/adaptive/StreamFormat.hpp b/modules/demux/adaptive/StreamFormat.hpp
index b4a978feab..7b3d49e1b4 100644
--- a/modules/demux/adaptive/StreamFormat.hpp
+++ b/modules/demux/adaptive/StreamFormat.hpp
@@ -37,6 +37,7 @@ namespace adaptive
             static const unsigned UNKNOWN     = 0xFF; /* will probe */
 
             StreamFormat( unsigned = UNSUPPORTED );
+            explicit StreamFormat( const std::string &mime );
             ~StreamFormat();
             operator unsigned() const;
             std::string str() const;
diff --git a/modules/demux/adaptive/plumbing/Demuxer.cpp b/modules/demux/adaptive/plumbing/Demuxer.cpp
index 5eca5df527..e05061aa37 100644
--- a/modules/demux/adaptive/plumbing/Demuxer.cpp
+++ b/modules/demux/adaptive/plumbing/Demuxer.cpp
@@ -27,6 +27,7 @@
 #include <vlc_stream.h>
 #include <vlc_demux.h>
 #include "SourceStream.hpp"
+#include "../StreamFormat.hpp"
 #include "CommandsQueue.hpp"
 #include "../ChunksSource.hpp"
 
diff --git a/modules/demux/dash/mpd/AdaptationSet.cpp b/modules/demux/dash/mpd/AdaptationSet.cpp
index c755503f53..ece9592cd8 100644
--- a/modules/demux/dash/mpd/AdaptationSet.cpp
+++ b/modules/demux/dash/mpd/AdaptationSet.cpp
@@ -46,7 +46,7 @@ AdaptationSet::~AdaptationSet()
 StreamFormat AdaptationSet::getStreamFormat() const
 {
     if(!getMimeType().empty())
-        return MPD::mimeToFormat(getMimeType());
+        return StreamFormat(getMimeType());
     else
         return BaseAdaptationSet::getStreamFormat();
 }
diff --git a/modules/demux/dash/mpd/MPD.cpp b/modules/demux/dash/mpd/MPD.cpp
index 16ec834905..accd752138 100644
--- a/modules/demux/dash/mpd/MPD.cpp
+++ b/modules/demux/dash/mpd/MPD.cpp
@@ -65,24 +65,6 @@ Profile MPD::getProfile() const
     return profile;
 }
 
-StreamFormat MPD::mimeToFormat(const std::string &mime)
-{
-    std::string::size_type pos = mime.find("/");
-    if(pos != std::string::npos)
-    {
-        std::string tail = mime.substr(pos + 1);
-        if(tail == "mp4")
-            return StreamFormat(StreamFormat::MP4);
-        else if (tail == "mp2t")
-            return StreamFormat(StreamFormat::MPEG2TS);
-        else if (tail == "vtt")
-            return StreamFormat(StreamFormat::WEBVTT);
-        else if (tail == "ttml+xml")
-            return StreamFormat(StreamFormat::TTML);
-    }
-    return StreamFormat();
-}
-
 void MPD::debug()
 {
     msg_Dbg(p_object, "MPD profile=%s mediaPresentationDuration=%" PRId64
diff --git a/modules/demux/dash/mpd/MPD.h b/modules/demux/dash/mpd/MPD.h
index 18415401f3..a515798d0e 100644
--- a/modules/demux/dash/mpd/MPD.h
+++ b/modules/demux/dash/mpd/MPD.h
@@ -48,8 +48,6 @@ namespace dash
                 virtual bool                    isLive() const;
                 virtual void                    debug();
 
-                static StreamFormat             mimeToFormat(const std::string &);
-
                 Property<ProgramInformation *>      programInfo;
 
             private:
diff --git a/modules/demux/dash/mpd/Representation.cpp b/modules/demux/dash/mpd/Representation.cpp
index 710901102c..d49af4df28 100644
--- a/modules/demux/dash/mpd/Representation.cpp
+++ b/modules/demux/dash/mpd/Representation.cpp
@@ -51,9 +51,9 @@ Representation::~Representation ()
 StreamFormat Representation::getStreamFormat() const
 {
     if(getMimeType().empty())
-        return MPD::mimeToFormat(adaptationSet->getMimeType());
+        return StreamFormat(adaptationSet->getMimeType());
     else
-        return MPD::mimeToFormat(getMimeType());
+        return StreamFormat(getMimeType());
 }
 
 TrickModeType*      Representation::getTrickModeType        () const



More information about the vlc-commits mailing list