[vlc-commits] [Git][videolan/vlc][master] sout: chromecast: fix exposed URL formatting
Steve Lhomme (@robUx4)
gitlab at videolan.org
Tue Mar 31 16:35:54 UTC 2026
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
5efe99a9 by Marvin Scholz at 2026-03-31T16:18:54+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
- - - - -
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
=====================================
@@ -133,10 +133,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,
vlc_tick_t input_length )
@@ -345,12 +364,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\":\"" << ( input_length > VLC_TICK_0 ? "BUFFERED" : "LIVE" ) << "\""
<< ",\"contentType\":\"" << mime << "\"";
=====================================
modules/stream_out/chromecast/chromecast_ctrl.cpp
=====================================
@@ -172,9 +172,7 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
if( unlikely(m_ctl_thread_interrupt == NULL) )
throw std::runtime_error( "error creating interrupt context" );
- 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/5efe99a912ce3ebc9d62829e91b0aed5280345ba
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/5efe99a912ce3ebc9d62829e91b0aed5280345ba
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list