[vlc-commits] chromecast: Store the media session id as an integer
Hugo Beauzée-Luyssen
git at videolan.org
Thu Feb 1 12:10:42 CET 2018
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu Feb 1 10:53:27 2018 +0100| [d28be9f17aeeb86cac0f5b3d99d6fd39c6665d6f] | committer: Hugo Beauzée-Luyssen
chromecast: Store the media session id as an integer
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d28be9f17aeeb86cac0f5b3d99d6fd39c6665d6f
---
modules/stream_out/chromecast/chromecast.h | 12 ++++----
.../chromecast/chromecast_communication.cpp | 20 ++++++-------
modules/stream_out/chromecast/chromecast_ctrl.cpp | 33 ++++++++++------------
3 files changed, 31 insertions(+), 34 deletions(-)
diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index 5f6bccd9ac..3b43aad80b 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -112,13 +112,13 @@ public:
void msgAuth();
void msgPlayerLoad( const std::string& destinationId, unsigned int i_port,
const std::string& mime, const vlc_meta_t *p_meta );
- void msgPlayerPlay( const std::string& destinationId, const std::string& mediaSessionId );
- void msgPlayerStop( const std::string& destinationId, const std::string& mediaSessionId );
- void msgPlayerPause( const std::string& destinationId, const std::string& mediaSessionId );
+ void msgPlayerPlay( const std::string& destinationId, int64_t mediaSessionId );
+ void msgPlayerStop( const std::string& destinationId, int64_t mediaSessionId );
+ void msgPlayerPause( const std::string& destinationId, int64_t mediaSessionId );
void msgPlayerGetStatus( const std::string& destinationId );
- void msgPlayerSeek( const std::string& destinationId, const std::string& mediaSessionId,
+ void msgPlayerSeek( const std::string& destinationId, int64_t mediaSessionId,
const std::string & currentTime );
- void msgPlayerSetVolume( const std::string& destinationId, const std::string& mediaSessionId,
+ void msgPlayerSetVolume( const std::string& destinationId, int64_t mediaSessionId,
float volume, bool mute);
ssize_t receive( uint8_t *p_data, size_t i_size, int i_timeout, bool *pb_timeout );
@@ -223,7 +223,7 @@ private:
std::string m_mime;
std::string m_appTransportId;
- std::string m_mediaSessionId;
+ int64_t m_mediaSessionId;
mutable vlc_mutex_t m_lock;
vlc_cond_t m_stateChangedCond;
diff --git a/modules/stream_out/chromecast/chromecast_communication.cpp b/modules/stream_out/chromecast/chromecast_communication.cpp
index 6d28f3d2ac..e20bb19817 100644
--- a/modules/stream_out/chromecast/chromecast_communication.cpp
+++ b/modules/stream_out/chromecast/chromecast_communication.cpp
@@ -321,9 +321,9 @@ void ChromecastCommunication::msgPlayerLoad( const std::string& destinationId, u
pushMediaPlayerMessage( destinationId, ss );
}
-void ChromecastCommunication::msgPlayerPlay( const std::string& destinationId, const std::string& mediaSessionId )
+void ChromecastCommunication::msgPlayerPlay( const std::string& destinationId, int64_t mediaSessionId )
{
- assert(!mediaSessionId.empty());
+ assert(mediaSessionId != 0);
std::stringstream ss;
ss << "{\"type\":\"PLAY\","
@@ -334,9 +334,9 @@ void ChromecastCommunication::msgPlayerPlay( const std::string& destinationId, c
pushMediaPlayerMessage( destinationId, ss );
}
-void ChromecastCommunication::msgPlayerStop( const std::string& destinationId, const std::string& mediaSessionId )
+void ChromecastCommunication::msgPlayerStop( const std::string& destinationId, int64_t mediaSessionId )
{
- assert(!mediaSessionId.empty());
+ assert(mediaSessionId != 0);
std::stringstream ss;
ss << "{\"type\":\"STOP\","
@@ -347,9 +347,9 @@ void ChromecastCommunication::msgPlayerStop( const std::string& destinationId, c
pushMediaPlayerMessage( destinationId, ss );
}
-void ChromecastCommunication::msgPlayerPause( const std::string& destinationId, const std::string& mediaSessionId )
+void ChromecastCommunication::msgPlayerPause( const std::string& destinationId, int64_t mediaSessionId )
{
- assert(!mediaSessionId.empty());
+ assert(mediaSessionId != 0);
std::stringstream ss;
ss << "{\"type\":\"PAUSE\","
@@ -360,9 +360,9 @@ void ChromecastCommunication::msgPlayerPause( const std::string& destinationId,
pushMediaPlayerMessage( destinationId, ss );
}
-void ChromecastCommunication::msgPlayerSetVolume( const std::string& destinationId, const std::string& mediaSessionId, float f_volume, bool b_mute )
+void ChromecastCommunication::msgPlayerSetVolume( const std::string& destinationId, int64_t mediaSessionId, float f_volume, bool b_mute )
{
- assert(!mediaSessionId.empty());
+ assert(mediaSessionId != 0);
if ( f_volume < 0.0 || f_volume > 1.0)
return;
@@ -377,9 +377,9 @@ void ChromecastCommunication::msgPlayerSetVolume( const std::string& destination
pushMediaPlayerMessage( destinationId, ss );
}
-void ChromecastCommunication::msgPlayerSeek( const std::string& destinationId, const std::string& mediaSessionId, const std::string& currentTime )
+void ChromecastCommunication::msgPlayerSeek( const std::string& destinationId, int64_t mediaSessionId, const std::string& currentTime )
{
- assert(!mediaSessionId.empty());
+ assert(mediaSessionId != 0);
std::stringstream ss;
ss << "{\"type\":\"SEEK\","
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 0729980344..0eba36e959 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -87,6 +87,7 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
int device_port, vlc_interrupt_t *p_interrupt, httpd_host_t *httpd_host)
: m_module(p_this)
, m_streaming_port(port)
+ , m_mediaSessionId( 0 )
, m_communication( p_this, device_addr.c_str(), device_port )
, m_state( Authenticating )
, m_eof( false )
@@ -264,7 +265,7 @@ void intf_sys_t::prepareHttpArtwork()
void intf_sys_t::setHasInput( const std::string mime_type )
{
vlc_mutex_locker locker(&m_lock);
- msg_Dbg( m_module, "Loading content for session:%s", m_mediaSessionId.c_str() );
+ msg_Dbg( m_module, "Loading content for session: %" PRId64, m_mediaSessionId );
this->m_mime = mime_type;
@@ -493,7 +494,7 @@ void intf_sys_t::processReceiverMessage( const castchannel::CastMessage& msg )
msg_Warn( m_module, "Media receiver application got closed." );
setState( Connected );
m_appTransportId = "";
- m_mediaSessionId = "";
+ m_mediaSessionId = 0;
}
break;
case Connected:
@@ -559,7 +560,7 @@ void intf_sys_t::processMediaMessage( const castchannel::CastMessage& msg )
if ( m_state != Ready && m_state != LoadFailed )
{
// The playback stopped
- m_mediaSessionId = "";
+ m_mediaSessionId = 0;
m_time_playback_started = VLC_TS_INVALID;
if ( m_state == Buffering )
setState( LoadFailed );
@@ -573,16 +574,12 @@ void intf_sys_t::processMediaMessage( const castchannel::CastMessage& msg )
}
else
{
- char session_id[32];
- if( snprintf( session_id, sizeof(session_id), "%" PRId64, (json_int_t) status[0]["mediaSessionId"] ) >= (int)sizeof(session_id) )
- {
- msg_Err( m_module, "snprintf() truncated string for mediaSessionId" );
- session_id[sizeof(session_id) - 1] = '\0';
- }
- if (session_id[0] && m_mediaSessionId != session_id) {
- if (!m_mediaSessionId.empty())
- msg_Warn( m_module, "different mediaSessionId detected %s was %s", session_id, this->m_mediaSessionId.c_str());
- m_mediaSessionId = session_id;
+ int64_t sessionId = (json_int_t) status[0]["mediaSessionId"];
+ if (m_mediaSessionId != sessionId) {
+ if (m_mediaSessionId != 0)
+ msg_Warn( m_module, "different mediaSessionId detected % " PRId64
+ " was %" PRId64, sessionId, m_mediaSessionId );
+ m_mediaSessionId = sessionId;
}
if (newPlayerState == "PLAYING")
@@ -676,7 +673,7 @@ void intf_sys_t::processConnectionMessage( const castchannel::CastMessage& msg )
// From this point on, we need to relaunch the media receiver app
vlc_mutex_locker locker(&m_lock);
m_appTransportId = "";
- m_mediaSessionId = "";
+ m_mediaSessionId = 0;
setState( Connected );
}
else
@@ -771,7 +768,7 @@ void intf_sys_t::requestPlayerStop()
m_art_stream = NULL;
}
- if ( m_mediaSessionId.empty() == true )
+ if ( m_mediaSessionId == 0 )
return;
queueMessage( Stop );
}
@@ -785,7 +782,7 @@ States intf_sys_t::state() const
void intf_sys_t::requestPlayerSeek(mtime_t pos)
{
vlc_mutex_locker locker(&m_lock);
- if ( m_mediaSessionId.empty() == true )
+ if ( m_mediaSessionId == 0 )
return;
if ( pos != VLC_TS_INVALID )
m_ts_local_start = pos;
@@ -798,14 +795,14 @@ void intf_sys_t::setPauseState(bool paused)
vlc_mutex_locker locker( &m_lock );
if ( !paused )
{
- if ( !m_mediaSessionId.empty() )
+ if ( m_mediaSessionId == 0 )
{
m_communication.msgPlayerPlay( m_appTransportId, m_mediaSessionId );
}
}
else
{
- if ( !m_mediaSessionId.empty() && m_state != Paused )
+ if ( m_mediaSessionId == 0 && m_state != Paused )
{
m_communication.msgPlayerPause( m_appTransportId, m_mediaSessionId );
}
More information about the vlc-commits
mailing list