[vlc-commits] chromecast: change msg return values
Thomas Guillem
git at videolan.org
Thu Feb 22 11:59:53 CET 2018
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Feb 20 16:55:12 2018 +0100| [a84b999cd9acd0fd20317decfdd73c1bac1e891c] | committer: Thomas Guillem
chromecast: change msg return values
All msg*() methods return kInvalidId on error, 1 or the receiver/player
request ID on success.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a84b999cd9acd0fd20317decfdd73c1bac1e891c
---
modules/stream_out/chromecast/chromecast.h | 43 +++++----
.../chromecast/chromecast_communication.cpp | 102 +++++++++++++--------
modules/stream_out/chromecast/chromecast_ctrl.cpp | 6 +-
3 files changed, 93 insertions(+), 58 deletions(-)
diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index d928524ef8..6808066ed0 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -104,24 +104,29 @@ public:
*/
void disconnect();
- int msgPing();
- int msgPong();
- int msgConnect( const std::string& destinationId );
-
- int msgReceiverLaunchApp();
- int msgReceiverGetStatus();
- int msgReceiverClose(const std::string& destinationId);
- int msgAuth();
- int msgPlayerLoad( const std::string& destinationId, unsigned int i_port,
- const std::string& mime, const vlc_meta_t *p_meta );
- int msgPlayerPlay( const std::string& destinationId, int64_t mediaSessionId );
- int msgPlayerStop( const std::string& destinationId, int64_t mediaSessionId );
- int msgPlayerPause( const std::string& destinationId, int64_t mediaSessionId );
- int msgPlayerGetStatus( const std::string& destinationId );
- int msgPlayerSeek( const std::string& destinationId, int64_t mediaSessionId,
- const std::string & currentTime );
- int msgPlayerSetVolume( const std::string& destinationId, int64_t mediaSessionId,
- float volume, bool mute);
+ static const unsigned kInvalidId = 0;
+
+ /* All msg*() methods return kInvalidId on error, 1 or the receiver/player
+ * request ID on success */
+
+ unsigned msgPing();
+ unsigned msgPong();
+ unsigned msgConnect( const std::string& destinationId );
+
+ unsigned msgReceiverLaunchApp();
+ unsigned msgReceiverGetStatus();
+ unsigned msgReceiverClose(const std::string& destinationId);
+ unsigned msgAuth();
+ unsigned msgPlayerLoad( const std::string& destinationId, unsigned int i_port,
+ const std::string& mime, const vlc_meta_t *p_meta );
+ unsigned msgPlayerPlay( const std::string& destinationId, int64_t mediaSessionId );
+ unsigned msgPlayerStop( const std::string& destinationId, int64_t mediaSessionId );
+ unsigned msgPlayerPause( const std::string& destinationId, int64_t mediaSessionId );
+ unsigned msgPlayerGetStatus( const std::string& destinationId );
+ unsigned msgPlayerSeek( const std::string& destinationId, int64_t mediaSessionId,
+ const std::string & currentTime );
+ unsigned 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 );
const std::string getServerIp()
@@ -138,6 +143,8 @@ private:
int pushMediaPlayerMessage( const std::string& destinationId, const std::stringstream & payload );
std::string GetMedia( unsigned int i_port, const std::string& mime,
const vlc_meta_t *p_meta );
+ unsigned getNextReceiverRequestId();
+ unsigned getNextRequestId();
private:
vlc_object_t* m_module;
diff --git a/modules/stream_out/chromecast/chromecast_communication.cpp b/modules/stream_out/chromecast/chromecast_communication.cpp
index 999b48421b..cce61eb689 100644
--- a/modules/stream_out/chromecast/chromecast_communication.cpp
+++ b/modules/stream_out/chromecast/chromecast_communication.cpp
@@ -167,68 +167,90 @@ ssize_t ChromecastCommunication::receive( uint8_t *p_data, size_t i_size, int i_
/*****************************************************************************
* Message preparation
*****************************************************************************/
-int ChromecastCommunication::msgAuth()
+unsigned ChromecastCommunication::getNextReceiverRequestId()
+{
+ unsigned id = m_receiver_requestId++;
+ return likely(id != 0) ? id : m_receiver_requestId++;
+}
+
+unsigned ChromecastCommunication::getNextRequestId()
+{
+ unsigned id = m_requestId++;
+ return likely(id != 0) ? id : m_requestId++;
+}
+
+unsigned ChromecastCommunication::msgAuth()
{
castchannel::DeviceAuthMessage authMessage;
authMessage.mutable_challenge();
return buildMessage(NAMESPACE_DEVICEAUTH, authMessage.SerializeAsString(),
- DEFAULT_CHOMECAST_RECEIVER, castchannel::CastMessage_PayloadType_BINARY);
+ DEFAULT_CHOMECAST_RECEIVER, castchannel::CastMessage_PayloadType_BINARY)
+ == VLC_SUCCESS ? 1 : kInvalidId;
}
-int ChromecastCommunication::msgPing()
+unsigned ChromecastCommunication::msgPing()
{
std::string s("{\"type\":\"PING\"}");
- return buildMessage( NAMESPACE_HEARTBEAT, s, DEFAULT_CHOMECAST_RECEIVER );
+ return buildMessage( NAMESPACE_HEARTBEAT, s, DEFAULT_CHOMECAST_RECEIVER )
+ == VLC_SUCCESS ? 1 : kInvalidId;
}
-int ChromecastCommunication::msgPong()
+unsigned ChromecastCommunication::msgPong()
{
std::string s("{\"type\":\"PONG\"}");
- return buildMessage( NAMESPACE_HEARTBEAT, s, DEFAULT_CHOMECAST_RECEIVER );
+ return buildMessage( NAMESPACE_HEARTBEAT, s, DEFAULT_CHOMECAST_RECEIVER )
+ == VLC_SUCCESS ? 1 : kInvalidId;
}
-int ChromecastCommunication::msgConnect( const std::string& destinationId )
+unsigned ChromecastCommunication::msgConnect( const std::string& destinationId )
{
std::string s("{\"type\":\"CONNECT\"}");
- return buildMessage( NAMESPACE_CONNECTION, s, destinationId );
+ return buildMessage( NAMESPACE_CONNECTION, s, destinationId )
+ == VLC_SUCCESS ? 1 : kInvalidId;
}
-int ChromecastCommunication::msgReceiverClose( const std::string& destinationId )
+unsigned ChromecastCommunication::msgReceiverClose( const std::string& destinationId )
{
std::string s("{\"type\":\"CLOSE\"}");
- return buildMessage( NAMESPACE_CONNECTION, s, destinationId );
+ return buildMessage( NAMESPACE_CONNECTION, s, destinationId )
+ == VLC_SUCCESS ? 1 : kInvalidId;
}
-int ChromecastCommunication::msgReceiverGetStatus()
+unsigned ChromecastCommunication::msgReceiverGetStatus()
{
+ unsigned id = getNextReceiverRequestId();
std::stringstream ss;
ss << "{\"type\":\"GET_STATUS\","
- << "\"requestId\":" << m_receiver_requestId++ << "}";
+ << "\"requestId\":" << id << "}";
- return buildMessage( NAMESPACE_RECEIVER, ss.str(), DEFAULT_CHOMECAST_RECEIVER );
+ return buildMessage( NAMESPACE_RECEIVER, ss.str(), DEFAULT_CHOMECAST_RECEIVER )
+ == VLC_SUCCESS ? id : kInvalidId;
}
-int ChromecastCommunication::msgReceiverLaunchApp()
+unsigned ChromecastCommunication::msgReceiverLaunchApp()
{
+ unsigned id = getNextReceiverRequestId();
std::stringstream ss;
ss << "{\"type\":\"LAUNCH\","
<< "\"appId\":\"" << APP_ID << "\","
- << "\"requestId\":" << m_receiver_requestId++ << "}";
+ << "\"requestId\":" << id << "}";
- return buildMessage( NAMESPACE_RECEIVER, ss.str(), DEFAULT_CHOMECAST_RECEIVER );
+ return buildMessage( NAMESPACE_RECEIVER, ss.str(), DEFAULT_CHOMECAST_RECEIVER )
+ == VLC_SUCCESS ? id : kInvalidId;
}
-int ChromecastCommunication::msgPlayerGetStatus( const std::string& destinationId )
+unsigned ChromecastCommunication::msgPlayerGetStatus( const std::string& destinationId )
{
+ unsigned id = getNextRequestId();
std::stringstream ss;
ss << "{\"type\":\"GET_STATUS\","
- << "\"requestId\":" << m_requestId++
+ << "\"requestId\":" << id
<< "}";
- return pushMediaPlayerMessage( destinationId, ss );
+ return pushMediaPlayerMessage( destinationId, ss ) == VLC_SUCCESS ? id : kInvalidId;
}
std::string ChromecastCommunication::GetMedia( unsigned int i_port,
@@ -305,61 +327,66 @@ std::string ChromecastCommunication::GetMedia( unsigned int i_port,
return ss.str();
}
-int ChromecastCommunication::msgPlayerLoad( const std::string& destinationId, unsigned int i_port,
+unsigned ChromecastCommunication::msgPlayerLoad( const std::string& destinationId, unsigned int i_port,
const std::string& mime, const vlc_meta_t *p_meta )
{
+ unsigned id = getNextRequestId();
std::stringstream ss;
ss << "{\"type\":\"LOAD\","
<< "\"media\":{" << GetMedia( i_port, mime, p_meta ) << "},"
<< "\"autoplay\":\"false\","
- << "\"requestId\":" << m_requestId++
+ << "\"requestId\":" << id
<< "}";
- return pushMediaPlayerMessage( destinationId, ss );
+ return pushMediaPlayerMessage( destinationId, ss ) == VLC_SUCCESS ? id : kInvalidId;
}
-int ChromecastCommunication::msgPlayerPlay( const std::string& destinationId, int64_t mediaSessionId )
+unsigned ChromecastCommunication::msgPlayerPlay( const std::string& destinationId, int64_t mediaSessionId )
{
assert(mediaSessionId != 0);
+ unsigned id = getNextRequestId();
std::stringstream ss;
ss << "{\"type\":\"PLAY\","
<< "\"mediaSessionId\":" << mediaSessionId << ","
- << "\"requestId\":" << m_requestId++
+ << "\"requestId\":" << id
<< "}";
- return pushMediaPlayerMessage( destinationId, ss );
+ return pushMediaPlayerMessage( destinationId, ss ) == VLC_SUCCESS ? id : kInvalidId;
}
-int ChromecastCommunication::msgPlayerStop( const std::string& destinationId, int64_t mediaSessionId )
+unsigned ChromecastCommunication::msgPlayerStop( const std::string& destinationId, int64_t mediaSessionId )
{
assert(mediaSessionId != 0);
+ unsigned id = getNextRequestId();
std::stringstream ss;
ss << "{\"type\":\"STOP\","
<< "\"mediaSessionId\":" << mediaSessionId << ","
- << "\"requestId\":" << m_requestId++
+ << "\"requestId\":" << id
<< "}";
- return pushMediaPlayerMessage( destinationId, ss );
+ return pushMediaPlayerMessage( destinationId, ss ) == VLC_SUCCESS ? id : kInvalidId;
}
-int ChromecastCommunication::msgPlayerPause( const std::string& destinationId, int64_t mediaSessionId )
+unsigned ChromecastCommunication::msgPlayerPause( const std::string& destinationId, int64_t mediaSessionId )
{
assert(mediaSessionId != 0);
+ unsigned id = getNextRequestId();
std::stringstream ss;
ss << "{\"type\":\"PAUSE\","
<< "\"mediaSessionId\":" << mediaSessionId << ","
- << "\"requestId\":" << m_requestId++
+ << "\"requestId\":" << id
<< "}";
- return pushMediaPlayerMessage( destinationId, ss );
+ return pushMediaPlayerMessage( destinationId, ss ) == VLC_SUCCESS ? id : kInvalidId;
}
-int ChromecastCommunication::msgPlayerSetVolume( const std::string& destinationId, int64_t mediaSessionId, float f_volume, bool b_mute )
+unsigned ChromecastCommunication::msgPlayerSetVolume( const std::string& destinationId, int64_t mediaSessionId, float f_volume, bool b_mute )
{
assert(mediaSessionId != 0);
+ unsigned id = getNextRequestId();
if ( f_volume < 0.0 || f_volume > 1.0)
return VLC_EGENERIC;
@@ -368,24 +395,25 @@ int ChromecastCommunication::msgPlayerSetVolume( const std::string& destinationI
ss << "{\"type\":\"SET_VOLUME\","
<< "\"volume\":{\"level\":" << f_volume << ",\"muted\":" << ( b_mute ? "true" : "false" ) << "},"
<< "\"mediaSessionId\":" << mediaSessionId << ","
- << "\"requestId\":" << m_requestId++
+ << "\"requestId\":" << id
<< "}";
- return pushMediaPlayerMessage( destinationId, ss );
+ return pushMediaPlayerMessage( destinationId, ss ) == VLC_SUCCESS ? id : kInvalidId;
}
-int ChromecastCommunication::msgPlayerSeek( const std::string& destinationId, int64_t mediaSessionId, const std::string& currentTime )
+unsigned ChromecastCommunication::msgPlayerSeek( const std::string& destinationId, int64_t mediaSessionId, const std::string& currentTime )
{
assert(mediaSessionId != 0);
+ unsigned id = getNextRequestId();
std::stringstream ss;
ss << "{\"type\":\"SEEK\","
<< "\"currentTime\":" << currentTime << ","
<< "\"mediaSessionId\":" << mediaSessionId << ","
- << "\"requestId\":" << m_requestId++
+ << "\"requestId\":" << id
<< "}";
- return pushMediaPlayerMessage( destinationId, ss );
+ return pushMediaPlayerMessage( destinationId, ss ) == VLC_SUCCESS ? id : kInvalidId;
}
/**
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index d8541bff55..b33462e5e8 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -941,9 +941,9 @@ bool intf_sys_t::requestPlayerSeek(mtime_t pos)
if( !isStatePlaying() || m_mediaSessionId == 0 )
return false;
- int ret = m_communication.msgPlayerSeek( m_appTransportId, m_mediaSessionId,
- timeVLCToCC( pos ) );
- if( ret == VLC_SUCCESS )
+ unsigned ret = m_communication.msgPlayerSeek( m_appTransportId, m_mediaSessionId,
+ timeVLCToCC( pos ) );
+ if( ret != ChromecastCommunication::kInvalidId )
{
setState( Seeking );
return true;
More information about the vlc-commits
mailing list