[vlc-devel] [PATCH 04/16] chromecast: tell the control class when there's a file to play or not

Steve Lhomme robux4 at videolabs.io
Thu Apr 28 14:18:37 CEST 2016


---
 modules/stream_out/chromecast/chromecast.h        |  3 ++
 modules/stream_out/chromecast/chromecast_ctrl.cpp | 63 +++++++++++++++++++----
 2 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index a8ab0be..4252ccf 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -81,6 +81,8 @@ struct intf_sys_t
     intf_sys_t(vlc_object_t * const p_this, int local_port, std::string device_addr, int device_port = 0);
     ~intf_sys_t();
 
+    void setHasInput( bool has_input, const std::string mime_type = "");
+
     vlc_object_t  * const p_module;
     const int      i_port;
     std::string    serverIP;
@@ -172,6 +174,7 @@ private:
     unsigned i_receiver_requestId;
     unsigned i_requestId;
 
+    bool           has_input;
     static void* ChromecastThread(void* p_data);
 };
 
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index e0f8b36..ba8599a 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -106,6 +106,7 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
  , cmd_status(NO_CMD_PENDING)
  , i_receiver_requestId(0)
  , i_requestId(0)
+ , has_input(false)
 {
     vlc_mutex_init(&lock);
     vlc_cond_init(&loadCommandCond);
@@ -120,6 +121,8 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
 
 intf_sys_t::~intf_sys_t()
 {
+    setHasInput( false );
+
     switch (getConnectionStatus())
     {
     case CHROMECAST_APP_STARTED:
@@ -142,6 +145,40 @@ intf_sys_t::~intf_sys_t()
     vlc_mutex_destroy(&lock);
 }
 
+void intf_sys_t::setHasInput( bool b_has_input, const std::string mime_type )
+{
+    vlc_mutex_locker locker(&lock);
+    msg_Dbg( p_module, "setHasInput device:%s session:%s",
+             targetIP.c_str(), mediaSessionId.c_str() );
+
+    this->has_input = b_has_input;
+    this->mime = mime_type;
+
+    if( this->has_input )
+    {
+        mutex_cleanup_push(&lock);
+        while (conn_status != CHROMECAST_APP_STARTED && conn_status != CHROMECAST_CONNECTION_DEAD)
+        {
+            msg_Dbg( p_module, "setHasInput waiting for Chromecast connection, current %d", conn_status);
+            vlc_cond_wait(&loadCommandCond, &lock);
+        }
+        vlc_cleanup_pop();
+
+        if (conn_status == CHROMECAST_CONNECTION_DEAD)
+        {
+            msg_Warn( p_module, "no Chromecast hook possible");
+            return;
+        }
+
+        if ( receiverState == RECEIVER_IDLE )
+        {
+            // we cannot start a new load when the last one is still processing
+            msgPlayerLoad();
+            setPlayerStatus(CMD_LOAD_SENT);
+        }
+    }
+}
+
 /**
  * @brief Connect to the Chromecast
  * @return the opened socket file descriptor or -1 on error
@@ -390,9 +427,10 @@ void intf_sys_t::processMessage(const castchannel::CastMessage &msg)
                 {
                     msgConnect(appTransportId);
                     setConnectionStatus(CHROMECAST_APP_STARTED);
-                    msgPlayerLoad();
-                    setPlayerStatus(CMD_LOAD_SENT);
-                    vlc_cond_signal(&loadCommandCond);
+                }
+                else
+                {
+                    msgPlayerGetStatus();
                 }
             }
             else
@@ -497,10 +535,18 @@ void intf_sys_t::processMessage(const castchannel::CastMessage &msg)
                     break;
 
                 case RECEIVER_IDLE:
-                    setPlayerStatus(NO_CMD_PENDING);
+                    if ( has_input )
+                        setPlayerStatus(NO_CMD_PENDING);
                     break;
                 }
             }
+
+            if ( cmd_status != CMD_LOAD_SENT && receiverState == RECEIVER_IDLE && has_input )
+            {
+                msg_Dbg( p_module, "the device missed the LOAD command");
+                msgPlayerLoad();
+                setPlayerStatus(CMD_LOAD_SENT);
+            }
         }
         else if (type == "LOAD_FAILED")
         {
@@ -533,6 +579,7 @@ void intf_sys_t::processMessage(const castchannel::CastMessage &msg)
         if (type == "CLOSE")
         {
             msg_Warn( p_module, "received close message");
+            setHasInput( false );
             vlc_mutex_locker locker(&lock);
             setConnectionStatus(CHROMECAST_CONNECTION_DEAD);
         }
@@ -625,21 +672,15 @@ void intf_sys_t::msgPlayerGetStatus()
 
 void intf_sys_t::msgPlayerLoad()
 {
-    char *psz_mime = var_InheritString(p_module, CONTROL_CFG_PREFIX "mime");
-    if (psz_mime == NULL)
-        return;
-
     std::stringstream ss;
     ss << "{\"type\":\"LOAD\","
        <<  "\"media\":{\"contentId\":\"http://" << serverIP << ":"
            << i_port
            << "/stream\","
        <<             "\"streamType\":\"LIVE\","
-       <<             "\"contentType\":\"" << std::string(psz_mime) << "\"},"
+       <<             "\"contentType\":\"" << mime << "\"},"
        <<  "\"requestId\":" << i_requestId++ << "}";
 
-    free(psz_mime);
-
     pushMediaPlayerMessage( ss );
 }
 
-- 
2.7.0



More information about the vlc-devel mailing list