vlc | branch: master | Steve Lhomme <[email protected]> | Mon Mar 21 16:06:14 2016 +0100| [f9c31fa0b109660025f62108eeb0126723ddc7b2] | committer: Jean-Baptiste Kempf
chromecast: keep track of the state of the device It can be either Idle, Playing, Buffering or Paused > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f9c31fa0b109660025f62108eeb0126723ddc7b2 --- modules/stream_out/chromecast/chromecast.h | 8 +++ modules/stream_out/chromecast/chromecast_ctrl.cpp | 55 ++++++++++++++++++--- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h index 5b0e947..d817528 100644 --- a/modules/stream_out/chromecast/chromecast.h +++ b/modules/stream_out/chromecast/chromecast.h @@ -59,6 +59,13 @@ enum connection_status CHROMECAST_CONNECTION_DEAD, }; +enum receiver_state { + RECEIVER_IDLE, + RECEIVER_PLAYING, + RECEIVER_BUFFERING, + RECEIVER_PAUSED, +}; + struct intf_sys_t { intf_sys_t(vlc_object_t * const p_this); @@ -71,6 +78,7 @@ struct intf_sys_t std::string appTransportId; std::string mediaSessionId; + receiver_state receiverState; int i_sock_fd; vlc_tls_creds_t *p_creds; diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp index dc6d503..c2639c5 100644 --- a/modules/stream_out/chromecast/chromecast_ctrl.cpp +++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp @@ -241,6 +241,7 @@ void intf_sys_t::buildMessage(const std::string & namespace_, *****************************************************************************/ intf_sys_t::intf_sys_t(vlc_object_t * const p_this) : p_module(p_this) + , receiverState(RECEIVER_IDLE) , p_tls(NULL) , conn_status(CHROMECAST_DISCONNECTED) , i_receiver_requestId(0) @@ -319,6 +320,7 @@ void intf_sys_t::disconnectChromecast() setConnectionStatus(CHROMECAST_DISCONNECTED); appTransportId = ""; mediaSessionId = ""; // this session is not valid anymore + receiverState = RECEIVER_IDLE; } } @@ -575,18 +577,55 @@ void intf_sys_t::processMessage(const castchannel::CastMessage &msg) status[0]["playerState"].operator const char *(), (int)(json_int_t) status[0]["mediaSessionId"]); - char session_id[32]; - if( snprintf( session_id, sizeof(session_id), "%" PRId64, (json_int_t) status[0]["mediaSessionId"] ) >= (int)sizeof(session_id) ) + vlc_mutex_locker locker(&lock); + receiver_state oldPlayerState = receiverState; + std::string newPlayerState = status[0]["playerState"].operator const char *(); + + if (newPlayerState == "IDLE") + receiverState = RECEIVER_IDLE; + else if (newPlayerState == "PLAYING") + receiverState = RECEIVER_PLAYING; + else if (newPlayerState == "BUFFERING") + receiverState = RECEIVER_BUFFERING; + else if (newPlayerState == "PAUSED") + receiverState = RECEIVER_PAUSED; + else if (!newPlayerState.empty()) + msg_Warn( p_module, "Unknown Chromecast state %s", newPlayerState.c_str()); + + if (receiverState == RECEIVER_IDLE) + mediaSessionId = ""; // this session is not valid anymore + else { - msg_Err( p_module, "snprintf() truncated string for mediaSessionId" ); - session_id[sizeof(session_id) - 1] = '\0'; - } - if (!mediaSessionId.empty() && session_id[0] && mediaSessionId != session_id) { - msg_Warn( p_module, "different mediaSessionId detected %s was %s", mediaSessionId.c_str(), this->mediaSessionId.c_str()); + char session_id[32]; + if( snprintf( session_id, sizeof(session_id), "%" PRId64, (json_int_t) status[0]["mediaSessionId"] ) >= (int)sizeof(session_id) ) + { + msg_Err( p_module, "snprintf() truncated string for mediaSessionId" ); + session_id[sizeof(session_id) - 1] = '\0'; + } + if (!mediaSessionId.empty() && session_id[0] && mediaSessionId != session_id) { + msg_Warn( p_module, "different mediaSessionId detected %s was %s", mediaSessionId.c_str(), this->mediaSessionId.c_str()); + } + + mediaSessionId = session_id; } - mediaSessionId = session_id; + if (receiverState != oldPlayerState) + { +#ifndef NDEBUG + msg_Dbg( p_module, "change Chromecast player state from %d to %d", oldPlayerState, receiverState); +#endif + switch( receiverState ) + { + case RECEIVER_PAUSED: +#ifndef NDEBUG + msg_Dbg( p_module, "Playback paused"); +#endif + break; + case RECEIVER_IDLE: + break; + } + } } else if (type == "LOAD_FAILED") { _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
