Commit 4921e9a2 authored by Steve Lhomme's avatar Steve Lhomme Committed by Jean-Baptiste Kempf

chromecast: reuse the same objects for namespaces

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent a459a47b
......@@ -317,7 +317,7 @@ static void Close(vlc_object_t *p_this)
p_sys->p_intf->msgReceiverClose(p_sys->p_intf->appTransportId);
// ft
case CHROMECAST_AUTHENTICATED:
p_sys->p_intf->msgReceiverClose("receiver-0");
p_sys->p_intf->msgReceiverClose(DEFAULT_CHOMECAST_RECEIVER);
// Send the just added close messages.
sendMessages(p_stream);
// ft
......@@ -577,7 +577,7 @@ static int processMessage(sout_stream_t *p_stream, const castchannel::CastMessag
sout_stream_sys_t *p_sys = p_stream->p_sys;
std::string namespace_ = msg.namespace_();
if (namespace_ == "urn:x-cast:com.google.cast.tp.deviceauth")
if (namespace_ == NAMESPACE_DEVICEAUTH)
{
castchannel::DeviceAuthMessage authMessage;
authMessage.ParseFromString(msg.payload_binary());
......@@ -596,11 +596,11 @@ static int processMessage(sout_stream_t *p_stream, const castchannel::CastMessag
{
vlc_mutex_locker locker(&p_sys->lock);
p_sys->i_status = CHROMECAST_AUTHENTICATED;
p_sys->p_intf->msgConnect("receiver-0");
p_sys->p_intf->msgConnect(DEFAULT_CHOMECAST_RECEIVER);
p_sys->p_intf->msgReceiverLaunchApp();
}
}
else if (namespace_ == "urn:x-cast:com.google.cast.tp.heartbeat")
else if (namespace_ == NAMESPACE_HEARTBEAT)
{
json_value *p_data = json_parse(msg.payload_utf8().c_str());
std::string type((*p_data)["type"]);
......@@ -622,7 +622,7 @@ static int processMessage(sout_stream_t *p_stream, const castchannel::CastMessag
json_value_free(p_data);
}
else if (namespace_ == "urn:x-cast:com.google.cast.receiver")
else if (namespace_ == NAMESPACE_RECEIVER)
{
json_value *p_data = json_parse(msg.payload_utf8().c_str());
std::string type((*p_data)["type"]);
......@@ -685,7 +685,7 @@ static int processMessage(sout_stream_t *p_stream, const castchannel::CastMessag
json_value_free(p_data);
}
else if (namespace_ == "urn:x-cast:com.google.cast.media")
else if (namespace_ == NAMESPACE_MEDIA)
{
json_value *p_data = json_parse(msg.payload_utf8().c_str());
std::string type((*p_data)["type"]);
......@@ -713,7 +713,7 @@ static int processMessage(sout_stream_t *p_stream, const castchannel::CastMessag
json_value_free(p_data);
}
else if (namespace_ == "urn:x-cast:com.google.cast.tp.connection")
else if (namespace_ == NAMESPACE_CONNECTION)
{
json_value *p_data = json_parse(msg.payload_utf8().c_str());
std::string type((*p_data)["type"]);
......
......@@ -36,6 +36,16 @@
#include "cast_channel.pb.h"
// Media player Chromecast app id
static const std::string DEFAULT_CHOMECAST_RECEIVER = "receiver-0";
static const std::string NAMESPACE_DEVICEAUTH = "urn:x-cast:com.google.cast.tp.deviceauth";
static const std::string NAMESPACE_CONNECTION = "urn:x-cast:com.google.cast.tp.connection";
static const std::string NAMESPACE_HEARTBEAT = "urn:x-cast:com.google.cast.tp.heartbeat";
static const std::string NAMESPACE_RECEIVER = "urn:x-cast:com.google.cast.receiver";
/* see https://developers.google.com/cast/docs/reference/messages */
static const std::string NAMESPACE_MEDIA = "urn:x-cast:com.google.cast.media";
// Status
enum
{
......
......@@ -89,7 +89,7 @@ void intf_sys_t::msgAuth()
std::string authMessageString;
authMessage.SerializeToString(&authMessageString);
castchannel::CastMessage msg = buildMessage("urn:x-cast:com.google.cast.tp.deviceauth",
castchannel::CastMessage msg = buildMessage(NAMESPACE_DEVICEAUTH,
castchannel::CastMessage_PayloadType_BINARY, authMessageString);
messagesToSend.push(msg);
......@@ -99,7 +99,7 @@ void intf_sys_t::msgAuth()
void intf_sys_t::msgPing()
{
std::string s("{\"type\":\"PING\"}");
castchannel::CastMessage msg = buildMessage("urn:x-cast:com.google.cast.tp.heartbeat",
castchannel::CastMessage msg = buildMessage(NAMESPACE_HEARTBEAT,
castchannel::CastMessage_PayloadType_STRING, s);
messagesToSend.push(msg);
......@@ -109,7 +109,7 @@ void intf_sys_t::msgPing()
void intf_sys_t::msgPong()
{
std::string s("{\"type\":\"PONG\"}");
castchannel::CastMessage msg = buildMessage("urn:x-cast:com.google.cast.tp.heartbeat",
castchannel::CastMessage msg = buildMessage(NAMESPACE_HEARTBEAT,
castchannel::CastMessage_PayloadType_STRING, s);
messagesToSend.push(msg);
......@@ -119,7 +119,7 @@ void intf_sys_t::msgPong()
void intf_sys_t::msgConnect(std::string destinationId)
{
std::string s("{\"type\":\"CONNECT\"}");
castchannel::CastMessage msg = buildMessage("urn:x-cast:com.google.cast.tp.connection",
castchannel::CastMessage msg = buildMessage(NAMESPACE_CONNECTION,
castchannel::CastMessage_PayloadType_STRING, s, destinationId);
messagesToSend.push(msg);
......@@ -129,7 +129,7 @@ void intf_sys_t::msgConnect(std::string destinationId)
void intf_sys_t::msgReceiverClose(std::string destinationId)
{
std::string s("{\"type\":\"CLOSE\"}");
castchannel::CastMessage msg = buildMessage("urn:x-cast:com.google.cast.tp.connection",
castchannel::CastMessage msg = buildMessage(NAMESPACE_CONNECTION,
castchannel::CastMessage_PayloadType_STRING, s, destinationId);
messagesToSend.push(msg);
......@@ -140,7 +140,7 @@ void intf_sys_t::msgReceiverGetStatus()
std::stringstream ss;
ss << "{\"type\":\"GET_STATUS\"}";
castchannel::CastMessage msg = buildMessage("urn:x-cast:com.google.cast.receiver",
castchannel::CastMessage msg = buildMessage(NAMESPACE_RECEIVER,
castchannel::CastMessage_PayloadType_STRING, ss.str());
messagesToSend.push(msg);
......@@ -153,7 +153,7 @@ void intf_sys_t::msgReceiverLaunchApp()
<< "\"appId\":\"" << APP_ID << "\","
<< "\"requestId\":" << i_requestId++ << "}";
castchannel::CastMessage msg = buildMessage("urn:x-cast:com.google.cast.receiver",
castchannel::CastMessage msg = buildMessage(NAMESPACE_RECEIVER,
castchannel::CastMessage_PayloadType_STRING, ss.str());
messagesToSend.push(msg);
......
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