Commit 57f014d7 authored by Thomas Guillem's avatar Thomas Guillem Committed by Jean-Baptiste Kempf

chromecast: return a VLC status from msg methods

(cherry picked from commit f9c3a40d)
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 2a252aa3
...@@ -104,24 +104,24 @@ public: ...@@ -104,24 +104,24 @@ public:
*/ */
void disconnect(); void disconnect();
void msgPing(); int msgPing();
void msgPong(); int msgPong();
void msgConnect( const std::string& destinationId ); int msgConnect( const std::string& destinationId );
void msgReceiverLaunchApp(); int msgReceiverLaunchApp();
void msgReceiverGetStatus(); int msgReceiverGetStatus();
void msgReceiverClose(const std::string& destinationId); int msgReceiverClose(const std::string& destinationId);
void msgAuth(); int msgAuth();
void msgPlayerLoad( const std::string& destinationId, unsigned int i_port, int msgPlayerLoad( const std::string& destinationId, unsigned int i_port,
const std::string& mime, const vlc_meta_t *p_meta ); const std::string& mime, const vlc_meta_t *p_meta );
void msgPlayerPlay( const std::string& destinationId, int64_t mediaSessionId ); int msgPlayerPlay( const std::string& destinationId, int64_t mediaSessionId );
void msgPlayerStop( const std::string& destinationId, int64_t mediaSessionId ); int msgPlayerStop( const std::string& destinationId, int64_t mediaSessionId );
void msgPlayerPause( const std::string& destinationId, int64_t mediaSessionId ); int msgPlayerPause( const std::string& destinationId, int64_t mediaSessionId );
void msgPlayerGetStatus( const std::string& destinationId ); int msgPlayerGetStatus( const std::string& destinationId );
void msgPlayerSeek( const std::string& destinationId, int64_t mediaSessionId, int msgPlayerSeek( const std::string& destinationId, int64_t mediaSessionId,
const std::string & currentTime ); const std::string & currentTime );
void msgPlayerSetVolume( const std::string& destinationId, int64_t mediaSessionId, int msgPlayerSetVolume( const std::string& destinationId, int64_t mediaSessionId,
float volume, bool mute); float volume, bool mute);
ssize_t receive( uint8_t *p_data, size_t i_size, int i_timeout, bool *pb_timeout ); ssize_t receive( uint8_t *p_data, size_t i_size, int i_timeout, bool *pb_timeout );
const std::string getServerIp() const std::string getServerIp()
...@@ -131,11 +131,11 @@ public: ...@@ -131,11 +131,11 @@ public:
private: private:
int sendMessage(const castchannel::CastMessage &msg); int sendMessage(const castchannel::CastMessage &msg);
void buildMessage(const std::string & namespace_, int buildMessage(const std::string & namespace_,
const std::string & payload, const std::string & payload,
const std::string & destinationId = DEFAULT_CHOMECAST_RECEIVER, const std::string & destinationId = DEFAULT_CHOMECAST_RECEIVER,
castchannel::CastMessage_PayloadType payloadType = castchannel::CastMessage_PayloadType_STRING); castchannel::CastMessage_PayloadType payloadType = castchannel::CastMessage_PayloadType_STRING);
void pushMediaPlayerMessage( const std::string& destinationId, const std::stringstream & payload ); int pushMediaPlayerMessage( const std::string& destinationId, const std::stringstream & payload );
std::string GetMedia( unsigned int i_port, const std::string& mime, std::string GetMedia( unsigned int i_port, const std::string& mime,
const vlc_meta_t *p_meta ); const vlc_meta_t *p_meta );
......
...@@ -90,7 +90,7 @@ void ChromecastCommunication::disconnect() ...@@ -90,7 +90,7 @@ void ChromecastCommunication::disconnect()
* @param destinationId the destination idenifier * @param destinationId the destination idenifier
* @return the generated CastMessage * @return the generated CastMessage
*/ */
void ChromecastCommunication::buildMessage(const std::string & namespace_, int ChromecastCommunication::buildMessage(const std::string & namespace_,
const std::string & payload, const std::string & payload,
const std::string & destinationId, const std::string & destinationId,
castchannel::CastMessage_PayloadType payloadType) castchannel::CastMessage_PayloadType payloadType)
...@@ -107,7 +107,7 @@ void ChromecastCommunication::buildMessage(const std::string & namespace_, ...@@ -107,7 +107,7 @@ void ChromecastCommunication::buildMessage(const std::string & namespace_,
else // CastMessage_PayloadType_BINARY else // CastMessage_PayloadType_BINARY
msg.set_payload_binary(payload); msg.set_payload_binary(payload);
sendMessage(msg); return sendMessage(msg);
} }
/** /**
...@@ -172,68 +172,68 @@ ssize_t ChromecastCommunication::receive( uint8_t *p_data, size_t i_size, int i_ ...@@ -172,68 +172,68 @@ ssize_t ChromecastCommunication::receive( uint8_t *p_data, size_t i_size, int i_
/***************************************************************************** /*****************************************************************************
* Message preparation * Message preparation
*****************************************************************************/ *****************************************************************************/
void ChromecastCommunication::msgAuth() int ChromecastCommunication::msgAuth()
{ {
castchannel::DeviceAuthMessage authMessage; castchannel::DeviceAuthMessage authMessage;
authMessage.mutable_challenge(); authMessage.mutable_challenge();
buildMessage(NAMESPACE_DEVICEAUTH, authMessage.SerializeAsString(), return buildMessage(NAMESPACE_DEVICEAUTH, authMessage.SerializeAsString(),
DEFAULT_CHOMECAST_RECEIVER, castchannel::CastMessage_PayloadType_BINARY); DEFAULT_CHOMECAST_RECEIVER, castchannel::CastMessage_PayloadType_BINARY);
} }
void ChromecastCommunication::msgPing() int ChromecastCommunication::msgPing()
{ {
std::string s("{\"type\":\"PING\"}"); std::string s("{\"type\":\"PING\"}");
buildMessage( NAMESPACE_HEARTBEAT, s, DEFAULT_CHOMECAST_RECEIVER ); return buildMessage( NAMESPACE_HEARTBEAT, s, DEFAULT_CHOMECAST_RECEIVER );
} }
void ChromecastCommunication::msgPong() int ChromecastCommunication::msgPong()
{ {
std::string s("{\"type\":\"PONG\"}"); std::string s("{\"type\":\"PONG\"}");
buildMessage( NAMESPACE_HEARTBEAT, s, DEFAULT_CHOMECAST_RECEIVER ); return buildMessage( NAMESPACE_HEARTBEAT, s, DEFAULT_CHOMECAST_RECEIVER );
} }
void ChromecastCommunication::msgConnect( const std::string& destinationId ) int ChromecastCommunication::msgConnect( const std::string& destinationId )
{ {
std::string s("{\"type\":\"CONNECT\"}"); std::string s("{\"type\":\"CONNECT\"}");
buildMessage( NAMESPACE_CONNECTION, s, destinationId ); return buildMessage( NAMESPACE_CONNECTION, s, destinationId );
} }
void ChromecastCommunication::msgReceiverClose( const std::string& destinationId ) int ChromecastCommunication::msgReceiverClose( const std::string& destinationId )
{ {
std::string s("{\"type\":\"CLOSE\"}"); std::string s("{\"type\":\"CLOSE\"}");
buildMessage( NAMESPACE_CONNECTION, s, destinationId ); return buildMessage( NAMESPACE_CONNECTION, s, destinationId );
} }
void ChromecastCommunication::msgReceiverGetStatus() int ChromecastCommunication::msgReceiverGetStatus()
{ {
std::stringstream ss; std::stringstream ss;
ss << "{\"type\":\"GET_STATUS\"," ss << "{\"type\":\"GET_STATUS\","
<< "\"requestId\":" << m_receiver_requestId++ << "}"; << "\"requestId\":" << m_receiver_requestId++ << "}";
buildMessage( NAMESPACE_RECEIVER, ss.str(), DEFAULT_CHOMECAST_RECEIVER ); return buildMessage( NAMESPACE_RECEIVER, ss.str(), DEFAULT_CHOMECAST_RECEIVER );
} }
void ChromecastCommunication::msgReceiverLaunchApp() int ChromecastCommunication::msgReceiverLaunchApp()
{ {
std::stringstream ss; std::stringstream ss;
ss << "{\"type\":\"LAUNCH\"," ss << "{\"type\":\"LAUNCH\","
<< "\"appId\":\"" << APP_ID << "\"," << "\"appId\":\"" << APP_ID << "\","
<< "\"requestId\":" << m_receiver_requestId++ << "}"; << "\"requestId\":" << m_receiver_requestId++ << "}";
buildMessage( NAMESPACE_RECEIVER, ss.str(), DEFAULT_CHOMECAST_RECEIVER ); return buildMessage( NAMESPACE_RECEIVER, ss.str(), DEFAULT_CHOMECAST_RECEIVER );
} }
void ChromecastCommunication::msgPlayerGetStatus( const std::string& destinationId ) int ChromecastCommunication::msgPlayerGetStatus( const std::string& destinationId )
{ {
std::stringstream ss; std::stringstream ss;
ss << "{\"type\":\"GET_STATUS\"," ss << "{\"type\":\"GET_STATUS\","
<< "\"requestId\":" << m_requestId++ << "\"requestId\":" << m_requestId++
<< "}"; << "}";
pushMediaPlayerMessage( destinationId, ss ); return pushMediaPlayerMessage( destinationId, ss );
} }
std::string ChromecastCommunication::GetMedia( unsigned int i_port, std::string ChromecastCommunication::GetMedia( unsigned int i_port,
...@@ -310,7 +310,7 @@ std::string ChromecastCommunication::GetMedia( unsigned int i_port, ...@@ -310,7 +310,7 @@ std::string ChromecastCommunication::GetMedia( unsigned int i_port,
return ss.str(); return ss.str();
} }
void ChromecastCommunication::msgPlayerLoad( const std::string& destinationId, unsigned int i_port, int ChromecastCommunication::msgPlayerLoad( const std::string& destinationId, unsigned int i_port,
const std::string& mime, const vlc_meta_t *p_meta ) const std::string& mime, const vlc_meta_t *p_meta )
{ {
std::stringstream ss; std::stringstream ss;
...@@ -320,10 +320,10 @@ void ChromecastCommunication::msgPlayerLoad( const std::string& destinationId, u ...@@ -320,10 +320,10 @@ void ChromecastCommunication::msgPlayerLoad( const std::string& destinationId, u
<< "\"requestId\":" << m_requestId++ << "\"requestId\":" << m_requestId++
<< "}"; << "}";
pushMediaPlayerMessage( destinationId, ss ); return pushMediaPlayerMessage( destinationId, ss );
} }
void ChromecastCommunication::msgPlayerPlay( const std::string& destinationId, int64_t mediaSessionId ) int ChromecastCommunication::msgPlayerPlay( const std::string& destinationId, int64_t mediaSessionId )
{ {
assert(mediaSessionId != 0); assert(mediaSessionId != 0);
...@@ -333,10 +333,10 @@ void ChromecastCommunication::msgPlayerPlay( const std::string& destinationId, i ...@@ -333,10 +333,10 @@ void ChromecastCommunication::msgPlayerPlay( const std::string& destinationId, i
<< "\"requestId\":" << m_requestId++ << "\"requestId\":" << m_requestId++
<< "}"; << "}";
pushMediaPlayerMessage( destinationId, ss ); return pushMediaPlayerMessage( destinationId, ss );
} }
void ChromecastCommunication::msgPlayerStop( const std::string& destinationId, int64_t mediaSessionId ) int ChromecastCommunication::msgPlayerStop( const std::string& destinationId, int64_t mediaSessionId )
{ {
assert(mediaSessionId != 0); assert(mediaSessionId != 0);
...@@ -346,10 +346,10 @@ void ChromecastCommunication::msgPlayerStop( const std::string& destinationId, i ...@@ -346,10 +346,10 @@ void ChromecastCommunication::msgPlayerStop( const std::string& destinationId, i
<< "\"requestId\":" << m_requestId++ << "\"requestId\":" << m_requestId++
<< "}"; << "}";
pushMediaPlayerMessage( destinationId, ss ); return pushMediaPlayerMessage( destinationId, ss );
} }
void ChromecastCommunication::msgPlayerPause( const std::string& destinationId, int64_t mediaSessionId ) int ChromecastCommunication::msgPlayerPause( const std::string& destinationId, int64_t mediaSessionId )
{ {
assert(mediaSessionId != 0); assert(mediaSessionId != 0);
...@@ -359,15 +359,15 @@ void ChromecastCommunication::msgPlayerPause( const std::string& destinationId, ...@@ -359,15 +359,15 @@ void ChromecastCommunication::msgPlayerPause( const std::string& destinationId,
<< "\"requestId\":" << m_requestId++ << "\"requestId\":" << m_requestId++
<< "}"; << "}";
pushMediaPlayerMessage( destinationId, ss ); return pushMediaPlayerMessage( destinationId, ss );
} }
void ChromecastCommunication::msgPlayerSetVolume( const std::string& destinationId, int64_t mediaSessionId, float f_volume, bool b_mute ) int ChromecastCommunication::msgPlayerSetVolume( const std::string& destinationId, int64_t mediaSessionId, float f_volume, bool b_mute )
{ {
assert(mediaSessionId != 0); assert(mediaSessionId != 0);
if ( f_volume < 0.0 || f_volume > 1.0) if ( f_volume < 0.0 || f_volume > 1.0)
return; return VLC_EGENERIC;
std::stringstream ss; std::stringstream ss;
ss << "{\"type\":\"SET_VOLUME\"," ss << "{\"type\":\"SET_VOLUME\","
...@@ -376,10 +376,10 @@ void ChromecastCommunication::msgPlayerSetVolume( const std::string& destination ...@@ -376,10 +376,10 @@ void ChromecastCommunication::msgPlayerSetVolume( const std::string& destination
<< "\"requestId\":" << m_requestId++ << "\"requestId\":" << m_requestId++
<< "}"; << "}";
pushMediaPlayerMessage( destinationId, ss ); return pushMediaPlayerMessage( destinationId, ss );
} }
void ChromecastCommunication::msgPlayerSeek( const std::string& destinationId, int64_t mediaSessionId, const std::string& currentTime ) int ChromecastCommunication::msgPlayerSeek( const std::string& destinationId, int64_t mediaSessionId, const std::string& currentTime )
{ {
assert(mediaSessionId != 0); assert(mediaSessionId != 0);
...@@ -390,7 +390,7 @@ void ChromecastCommunication::msgPlayerSeek( const std::string& destinationId, i ...@@ -390,7 +390,7 @@ void ChromecastCommunication::msgPlayerSeek( const std::string& destinationId, i
<< "\"requestId\":" << m_requestId++ << "\"requestId\":" << m_requestId++
<< "}"; << "}";
pushMediaPlayerMessage( destinationId, ss ); return pushMediaPlayerMessage( destinationId, ss );
} }
/** /**
...@@ -422,8 +422,8 @@ int ChromecastCommunication::sendMessage( const castchannel::CastMessage &msg ) ...@@ -422,8 +422,8 @@ int ChromecastCommunication::sendMessage( const castchannel::CastMessage &msg )
return VLC_EGENERIC; return VLC_EGENERIC;
} }
void ChromecastCommunication::pushMediaPlayerMessage( const std::string& destinationId, const std::stringstream & payload ) int ChromecastCommunication::pushMediaPlayerMessage( const std::string& destinationId, const std::stringstream & payload )
{ {
assert(!destinationId.empty()); assert(!destinationId.empty());
buildMessage( NAMESPACE_MEDIA, payload.str(), destinationId ); return buildMessage( NAMESPACE_MEDIA, payload.str(), destinationId );
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment