[vlc-commits] sout: chromecast: use stream info helpers for ChromecastCommuncation

Filip Roséen git at videolan.org
Tue Jul 24 16:03:29 CEST 2018


vlc | branch: master | Filip Roséen <filip at atch.se> | Mon Jul 23 19:57:01 2018 +0200| [c4d351ccfb6990d2ba1b4996e1a582aa5e6d8f85] | committer: Jean-Baptiste Kempf

sout: chromecast: use stream info helpers for ChromecastCommuncation

Both the path and port are available upon construction of the
ChromecastCommuncation, they also do not change during the lifetime of
the object.

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

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

 modules/stream_out/chromecast/chromecast.h                 | 11 +++++++----
 modules/stream_out/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 739cfb0d59..388c158fdc 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;
 }



More information about the vlc-commits mailing list