[vlc-devel] HLS and Wowza

Robert Forsman bob.forsman at ericsson.com
Mon May 14 17:19:24 CEST 2012


On Mon, 14 May 2012 08:21:10 -0400
Frederic YHUEL <fyhuel at viotech.net> wrote:

> The solution would be to write a proper function to make an absolute
> URI out of a base and relative path, in VLC core, as Rémi told me on
> IRC.
> 

A couple of months back when the DASH module couldn't handle relative
URLs I submitted the following code:

Feel free to use it as a starting point

diff --git a/modules/stream_filter/dash/mpd/BaseUrl.h b/modules/stream_filter/dash/mpd/BaseUrl.h
index f7b5548..bcbb1ed 100644
--- a/modules/stream_filter/dash/mpd/BaseUrl.h
+++ b/modules/stream_filter/dash/mpd/BaseUrl.h
@@ -38,7 +38,11 @@ namespace dash
                 virtual ~BaseUrl()                  {}
 
                 const std::string& getUrl() const { return this->url; }
+               std::string maybeRelative(std::string spec) const;
 
+               std::string protoHostPort() const;
+
+               static bool hasProtocol(const std::string&);
             private:
                 std::string url;
         };

diff --git a/modules/stream_filter/dash/mpd/BaseUrl.cpp
b/modules/stream_filter/dash/mpd/BaseUrl.cpp new file mode 100644
index 0000000..6b989ab
--- /dev/null
+++ b/modules/stream_filter/dash/mpd/BaseUrl.cpp
@@ -0,0 +1,53 @@
+#include "../exceptions/MalformedURLException.h"
+#include "BaseUrl.h"
+
+
+std::string  dash::mpd::BaseUrl::maybeRelative(std::string spec) const
+{
+    if (spec[0] == '/') {
+       return protoHostPort()+spec;
+
+    } else if (hasProtocol(spec)) {
+       return spec;
+
+    } else {
+       int idx = url.rfind('/');
+       if (idx<0)
+           throw dash::exception::MalformedURLException(url.c_str());
+
+       return url.substr(0, idx+1) + spec;
+    }
+}
+
+/**
+returns the http://host:port without a trailing /
+ */
+std::string dash::mpd::BaseUrl::protoHostPort() const
+{
+    int i1 = url.find("://");
+    if (i1<0)
+       throw dash::exception::MalformedURLException(url.c_str());
+    int i2 = url.find('/', i1+3);
+    if (i2<0)
+       throw dash::exception::MalformedURLException(url.c_str());
+
+    return url.substr(0, i2);
+}
+
+/**
+   if spec matches /^[a-z]+:/ then it has a "protocol" on the front
+ */
+bool dash::mpd::BaseUrl::hasProtocol(const std::string &spec)
+{
+    for (int i=0; i<spec.length(); i++) {
+       char ch = spec[i];
+       // yeah, I'm just faking it.  Maybe read the RFC later.
+       if (ch == ':') {
+           return i>0;
+       } else if ((ch<'a' || ch > 'z') && (ch < 'A' || ch > 'Z')) {
+           return false;
+       }
+    }
+
+    return false;
+}



More information about the vlc-devel mailing list