[vlc-commits] chromecast: delay the Demux() call until the Chromecast is ready to receive data

Steve Lhomme git at videolan.org
Wed Jun 15 01:43:05 CEST 2016


vlc | branch: master | Steve Lhomme <robux4 at videolabs.io> | Wed Jun 15 00:39:16 2016 +0200| [c3348c4bbe00e2001272faa1e5c9ab3f0ec0c267] | committer: Jean-Baptiste Kempf

chromecast: delay the Demux() call until the Chromecast is ready to receive data

Otherwise we start sending data while the connection is being established and
we miss the beginning of the file.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/stream_out/chromecast/chromecast.h         |    4 ++++
 modules/stream_out/chromecast/chromecast_common.h  |    2 ++
 modules/stream_out/chromecast/chromecast_ctrl.cpp  |   17 +++++++++++++++++
 modules/stream_out/chromecast/chromecast_demux.cpp |   10 ++++++++++
 4 files changed, 33 insertions(+)

diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index 4e10858..53557ef 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -130,6 +130,8 @@ private:
         }
     }
 
+    void waitAppStarted();
+
     int connectChromecast();
     void disconnectChromecast();
 
@@ -225,6 +227,8 @@ private:
     static void set_length(void*, mtime_t length);
     static mtime_t get_time(void*);
     static double get_position(void*);
+
+    static void wait_app_started(void*);
 };
 
 #endif /* VLC_CHROMECAST_H */
diff --git a/modules/stream_out/chromecast/chromecast_common.h b/modules/stream_out/chromecast/chromecast_common.h
index cfab0bf..a86f2b6 100644
--- a/modules/stream_out/chromecast/chromecast_common.h
+++ b/modules/stream_out/chromecast/chromecast_common.h
@@ -38,6 +38,8 @@ typedef struct
     void (*pf_set_length)(void*, mtime_t length);
     mtime_t (*pf_get_time)(void*);
     double (*pf_get_position)(void*);
+
+    void (*pf_wait_app_started)(void*);
 } chromecast_common;
 
 # ifdef __cplusplus
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 840c043..3d690c0 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -121,6 +121,7 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
     common.pf_get_position     = get_position;
     common.pf_get_time         = get_time;
     common.pf_set_length       = set_length;
+    common.pf_wait_app_started = wait_app_started;
 
     assert( var_Type( p_module->p_parent->p_parent, CC_SHARED_VAR_NAME) == 0 );
     if (var_Create( p_module->p_parent->p_parent, CC_SHARED_VAR_NAME, VLC_VAR_ADDRESS ) == VLC_SUCCESS )
@@ -976,6 +977,16 @@ void intf_sys_t::requestPlayerSeek()
     notifySendRequest();
 }
 
+void intf_sys_t::waitAppStarted()
+{
+    vlc_mutex_locker locker(&lock);
+    mutex_cleanup_push(&lock);
+    while ( conn_status != CHROMECAST_APP_STARTED &&
+            conn_status != CHROMECAST_CONNECTION_DEAD )
+        vlc_cond_wait(&loadCommandCond, &lock);
+    vlc_cleanup_pop();
+}
+
 mtime_t intf_sys_t::get_time(void *pt)
 {
     intf_sys_t *p_this = reinterpret_cast<intf_sys_t*>(pt);
@@ -995,3 +1006,9 @@ void intf_sys_t::set_length(void *pt, mtime_t length)
     intf_sys_t *p_this = reinterpret_cast<intf_sys_t*>(pt);
     p_this->i_length = length;
 }
+
+void intf_sys_t::wait_app_started(void *pt)
+{
+    intf_sys_t *p_this = reinterpret_cast<intf_sys_t*>(pt);
+    p_this->waitAppStarted();
+}
diff --git a/modules/stream_out/chromecast/chromecast_demux.cpp b/modules/stream_out/chromecast/chromecast_demux.cpp
index 9378a7e..aa4968a 100644
--- a/modules/stream_out/chromecast/chromecast_demux.cpp
+++ b/modules/stream_out/chromecast/chromecast_demux.cpp
@@ -41,6 +41,7 @@ struct demux_sys_t
     demux_sys_t(demux_t * const demux, chromecast_common * const renderer)
         :p_demux(demux)
         ,p_renderer(renderer)
+        ,demuxReady(false)
     {
     }
 
@@ -69,12 +70,21 @@ struct demux_sys_t
 
     int Demux()
     {
+        if (!demuxReady)
+        {
+            msg_Dbg(p_demux, "wait to demux");
+            p_renderer->pf_wait_app_started( p_renderer->p_opaque );
+            demuxReady = true;
+            msg_Dbg(p_demux, "ready to demux");
+        }
+
         return demux_Demux( p_demux->p_next );
     }
 
 protected:
     demux_t     * const p_demux;
     chromecast_common  * const p_renderer;
+    bool          demuxReady;
 };
 
 static int Demux( demux_t *p_demux_filter )



More information about the vlc-commits mailing list