[vlc-commits] [Git][videolan/vlc][3.0.x] sout: chromecast: fix exposed URL formatting

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Oct 31 03:23:00 UTC 2026



Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC


Commits:
2c5595ee by Marvin Scholz at 2026-10-31T03:09:34+00:00
sout: chromecast: fix exposed URL formatting

Chromecast devices need to know the local IP address to reach or HTTP
server, serving both media and art cover.
We use `net_GetSockAddress` to retrieve the host IP address, which does
not specify the IP version. Contacting a chromecast via IPv6 often leads
to `net_GetSockAddress` giving the host IPv6, which is fine, but needs
proper formatting.

Bracketing the IPv6 address is mandatory according to RFC 3986.

Co-Authored-By: Alaric Senat <alaric at videolabs.io>

Ref #29544

(cherry picked from commit 5efe99a912ce3ebc9d62829e91b0aed5280345ba)
Signed-off-by: Felix Paul Kühne <fkuehne at videolan.org>

- - - - -


3 changed files:

- modules/stream_out/chromecast/chromecast.h
- modules/stream_out/chromecast/chromecast_communication.cpp
- modules/stream_out/chromecast/chromecast_ctrl.cpp


Changes:

=====================================
modules/stream_out/chromecast/chromecast.h
=====================================
@@ -131,10 +131,8 @@ public:
                                  float volume, bool mute);
     ssize_t receive( uint8_t *p_data, size_t i_size, int i_timeout, bool *pb_timeout );
 
-    const std::string getServerIp()
-    {
-        return m_serverIp;
-    }
+    std::string getServerBaseURL() const;
+
 private:
     int sendMessage(const castchannel::CastMessage &msg);
 


=====================================
modules/stream_out/chromecast/chromecast_communication.cpp
=====================================
@@ -34,6 +34,8 @@
 
 #include <iomanip>
 
+#include <vlc_url.h>
+
 ChromecastCommunication::ChromecastCommunication( vlc_object_t* p_module,
     std::string serverPath, unsigned int serverPort, const char* targetIP, unsigned int devicePort )
     : m_module( p_module )
@@ -283,6 +285,23 @@ static std::string meta_get_escaped(const vlc_meta_t *p_meta, vlc_meta_type_t ty
     return escape_json(std::string(psz));
 }
 
+std::string ChromecastCommunication::getServerBaseURL() const
+{
+
+    vlc_url_t url_comps{};
+    url_comps.psz_protocol = (char*)"http";
+    url_comps.psz_host = (char*)m_serverIp.c_str();
+    url_comps.i_port = m_serverPort;
+
+    char *url = vlc_uri_compose(&url_comps);
+    if (!url)
+        throw std::bad_alloc();
+    std::string url_str = url;
+    std::free(url);
+
+    return url_str;
+}
+
 std::string ChromecastCommunication::GetMedia( const std::string& mime,
                                                const vlc_meta_t *p_meta )
 {
@@ -344,12 +363,11 @@ std::string ChromecastCommunication::GetMedia( const std::string& mime,
         }
     }
 
-    std::stringstream chromecast_url;
-    chromecast_url << "http://" << m_serverIp << ":" << m_serverPort << m_serverPath;
+    const std::string chromecast_url = getServerBaseURL() + m_serverPath;
 
-    msg_Dbg( m_module, "s_chromecast_url: %s", chromecast_url.str().c_str());
+    msg_Dbg( m_module, "s_chromecast_url: %s", chromecast_url.c_str());
 
-    ss << "\"contentId\":\"" << chromecast_url.str() << "\""
+    ss << "\"contentId\":\"" << chromecast_url << "\""
        << ",\"streamType\":\"LIVE\""
        << ",\"contentType\":\"" << mime << "\"";
 


=====================================
modules/stream_out/chromecast/chromecast_ctrl.cpp
=====================================
@@ -131,9 +131,7 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
     vlc_cond_init( &m_stateChangedCond );
     vlc_cond_init( &m_pace_cond );
 
-    std::stringstream ss;
-    ss << "http://" << m_communication->getServerIp() << ":" << port;
-    m_art_http_ip = ss.str();
+    m_art_http_ip = m_communication->getServerBaseURL();
 
     char *device_name = var_GetString(p_this, "sout-chromecast-device-name");
     if (device_name)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/2c5595eee24b29546507905784989ebdc526057e

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/2c5595eee24b29546507905784989ebdc526057e
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list