[vlc-devel] [PATCH 5/6] sout: chromecast: use stream info helpers for ChromecastCommuncation

Filip Roséen filip at atch.se
Mon Jul 23 19:57:01 CEST 2018


Both the path and port are available upon construction of the
ChromecastCommuncation, they also do not change during the lifetime of
the object.
---
 modules/stream_out/chromecast/chromecast.h         | 11 +++++++----
 .../chromecast/chromecast_communication.cpp        | 14 ++++++++------
 modules/stream_out/chromecast/chromecast_ctrl.cpp  | 10 ++++++----
 3 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index dcc2c4bc27..01dd76ee24 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -97,7 +97,9 @@ enum States
 class ChromecastCommunication
 {
 public:
-    ChromecastCommunication( vlc_object_t* module, const char* targetIP, unsigned int devicePort );
+    ChromecastCommunication( vlc_object_t* module,
+                             std::string serverPath, unsigned int serverPort,
+                             const char* targetIP, unsigned int devicePort );
     ~ChromecastCommunication();
     /**
      * @brief disconnect close the connection with the chromecast
@@ -117,7 +119,7 @@ public:
     unsigned msgReceiverGetStatus();
     unsigned msgReceiverClose(const std::string& destinationId);
     unsigned msgAuth();
-    unsigned msgPlayerLoad( const std::string& destinationId, unsigned int i_port,
+    unsigned msgPlayerLoad( const std::string& destinationId,
                             const std::string& mime, const vlc_meta_t *p_meta );
     unsigned msgPlayerPlay( const std::string& destinationId, int64_t mediaSessionId );
     unsigned msgPlayerStop( const std::string& destinationId, int64_t mediaSessionId );
@@ -141,8 +143,7 @@ private:
                      const std::string & destinationId = DEFAULT_CHOMECAST_RECEIVER,
                      castchannel::CastMessage_PayloadType payloadType = castchannel::CastMessage_PayloadType_STRING);
     int pushMediaPlayerMessage( const std::string& destinationId, const std::stringstream & payload );
-    std::string GetMedia( unsigned int i_port, const std::string& mime,
-                          const vlc_meta_t *p_meta );
+    std::string GetMedia( const std::string& mime, const vlc_meta_t *p_meta );
     unsigned getNextReceiverRequestId();
     unsigned getNextRequestId();
 
@@ -153,6 +154,8 @@ private:
     unsigned m_receiver_requestId;
     unsigned m_requestId;
     std::string m_serverIp;
+    const std::string m_serverPath;
+    const unsigned m_serverPort;
 };
 
 /*****************************************************************************
diff --git a/modules/stream_out/chromecast/chromecast_communication.cpp b/modules/stream_out/chromecast/chromecast_communication.cpp
index 2574df3a46..4d339f5efd 100644
--- a/modules/stream_out/chromecast/chromecast_communication.cpp
+++ b/modules/stream_out/chromecast/chromecast_communication.cpp
@@ -34,12 +34,15 @@
 
 #include <iomanip>
 
-ChromecastCommunication::ChromecastCommunication( vlc_object_t* p_module, const char* targetIP, unsigned int devicePort )
+ChromecastCommunication::ChromecastCommunication( vlc_object_t* p_module,
+    std::string serverPath, unsigned int serverPort, const char* targetIP, unsigned int devicePort )
     : m_module( p_module )
     , m_creds( NULL )
     , m_tls( NULL )
     , m_receiver_requestId( 1 )
     , m_requestId( 1 )
+    , m_serverPath( serverPath )
+    , m_serverPort( serverPort )
 {
     if (devicePort == 0)
         devicePort = CHROMECAST_CONTROL_PORT;
@@ -278,8 +281,7 @@ 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::GetMedia( unsigned int i_port,
-                                               const std::string& mime,
+std::string ChromecastCommunication::GetMedia( const std::string& mime,
                                                const vlc_meta_t *p_meta )
 {
     std::stringstream ss;
@@ -341,7 +343,7 @@ std::string ChromecastCommunication::GetMedia( unsigned int i_port,
     }
 
     std::stringstream chromecast_url;
-    chromecast_url << "http://" << m_serverIp << ":" << i_port << "/stream";
+    chromecast_url << "http://" << m_serverIp << ":" << m_serverPort << m_serverPath;
 
     msg_Dbg( m_module, "s_chromecast_url: %s", chromecast_url.str().c_str());
 
@@ -352,13 +354,13 @@ std::string ChromecastCommunication::GetMedia( unsigned int i_port,
     return ss.str();
 }
 
-unsigned ChromecastCommunication::msgPlayerLoad( const std::string& destinationId, unsigned int i_port,
+unsigned ChromecastCommunication::msgPlayerLoad( const std::string& destinationId,
                                              const std::string& mime, const vlc_meta_t *p_meta )
 {
     unsigned id = getNextRequestId();
     std::stringstream ss;
     ss << "{\"type\":\"LOAD\","
-       <<  "\"media\":{" << GetMedia( i_port, mime, p_meta ) << "},"
+       <<  "\"media\":{" << GetMedia( mime, p_meta ) << "},"
        <<  "\"autoplay\":\"false\","
        <<  "\"requestId\":" << id
        << "}";
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index bc59bbec3f..6f55fa3e23 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -118,8 +118,9 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
  , m_pause_delay( VLC_TICK_INVALID )
  , m_pingRetriesLeft( PING_WAIT_RETRIES )
 {
-    m_communication = new ChromecastCommunication( p_this, m_device_addr.c_str(),
-                                                   m_device_port );
+    m_communication = new ChromecastCommunication( p_this,
+        getHttpStreamPath(), getHttpStreamPort(),
+        m_device_addr.c_str(), m_device_port );
 
     m_ctl_thread_interrupt = vlc_interrupt_create();
     if( unlikely(m_ctl_thread_interrupt == NULL) )
@@ -223,6 +224,8 @@ void intf_sys_t::reinit()
     try
     {
         m_communication = new ChromecastCommunication( m_module,
+                                                       getHttpStreamPath(),
+                                                       getHttpStreamPort(),
                                                        m_device_addr.c_str(),
                                                        m_device_port );
     } catch (const std::runtime_error& err )
@@ -371,8 +374,7 @@ void intf_sys_t::tryLoad()
     // Reset the mediaSessionID to allow the new session to become the current one.
     // we cannot start a new load when the last one is still processing
     m_last_request_id =
-        m_communication->msgPlayerLoad( m_appTransportId, m_streaming_port,
-                                       m_mime, m_meta );
+        m_communication->msgPlayerLoad( m_appTransportId, m_mime, m_meta );
     if( m_last_request_id != ChromecastCommunication::kInvalidId )
         m_state = Loading;
 }
-- 
2.18.0


More information about the vlc-devel mailing list