[vlc-devel] [PATCH 04/10] chromecast: delay the Demux() call until the Chromecast is ready to receive data
Steve Lhomme
robux4 at videolabs.io
Tue May 31 13:15:31 CEST 2016
Otherwise we start sending data while the connection is being established and
we miss the beginning of the file.
---
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 8c27272..04d6586 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 64fc411..d8b7b41 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_filter_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_FilterDemuxNext( p_demux );
}
protected:
demux_filter_t * const p_demux;
chromecast_common * const p_renderer;
+ bool demuxReady;
};
static int Demux( demux_filter_t *p_demux_filter )
--
2.7.0
More information about the vlc-devel
mailing list