[vlc-devel] [PATCH 3/6] chromecast: factorize some strings
Steve Lhomme
robux4 at videolabs.io
Wed Oct 7 15:36:39 CEST 2015
---
modules/stream_out/chromecast/cast.cpp | 35 ++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/stream_out/chromecast/cast.cpp
index dfab8b3..88a9ee7 100644
--- a/modules/stream_out/chromecast/cast.cpp
+++ b/modules/stream_out/chromecast/cast.cpp
@@ -95,7 +95,7 @@ struct sout_stream_sys_t
};
// Media player Chromecast app id
-#define APP_ID "CC1AD845" // Default media player
+#define APP_ID "CC1AD845" // Default media player aka DEFAULT_MEDIA_RECEIVER_APPLICATION_ID
#define CHROMECAST_CONTROL_PORT 8009
#define HTTP_PORT 8010
@@ -109,6 +109,13 @@ struct sout_stream_sys_t
#define PONG_WAIT_TIME 500
#define PONG_WAIT_RETRIES 2
+static const char NAMESPACE_DEVICEAUTH[] = "urn:x-cast:com.google.cast.tp.deviceauth";
+static const char NAMESPACE_CONNECTION[] = "urn:x-cast:com.google.cast.tp.connection";
+static const char NAMESPACE_HEARTBEAT[] = "urn:x-cast:com.google.cast.tp.heartbeat";
+static const char NAMESPACE_RECEIVER[] = "urn:x-cast:com.google.cast.receiver";
+/* see https://developers.google.com/cast/docs/reference/messages */
+static const char NAMESPACE_MEDIA[] = "urn:x-cast:com.google.cast.media";
+
/*****************************************************************************
* Local prototypes
*****************************************************************************/
@@ -601,7 +608,7 @@ static int processMessage(sout_stream_t *p_stream, const castchannel::CastMessag
msg_Dbg(p_stream,"processMessage: %s payload:%s", namespace_.c_str(), msg.payload_utf8().c_str());
#endif
- if (namespace_ == "urn:x-cast:com.google.cast.tp.deviceauth")
+ if (namespace_ == NAMESPACE_DEVICEAUTH)
{
castchannel::DeviceAuthMessage authMessage;
authMessage.ParseFromString(msg.payload_binary());
@@ -624,7 +631,7 @@ static int processMessage(sout_stream_t *p_stream, const castchannel::CastMessag
msgLaunch(p_stream);
}
}
- 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"]);
@@ -646,7 +653,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"]);
@@ -709,7 +716,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"]);
@@ -737,7 +744,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"]);
@@ -808,7 +815,7 @@ static void msgAuth(sout_stream_t *p_stream)
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);
p_sys->messagesToSend.push(msg);
@@ -820,7 +827,7 @@ static void msgPing(sout_stream_t *p_stream)
sout_stream_sys_t *p_sys = p_stream->p_sys;
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);
p_sys->messagesToSend.push(msg);
@@ -832,7 +839,7 @@ static void msgPong(sout_stream_t *p_stream)
sout_stream_sys_t *p_sys = p_stream->p_sys;
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);
p_sys->messagesToSend.push(msg);
@@ -844,7 +851,7 @@ static void msgConnect(sout_stream_t *p_stream, std::string destinationId)
sout_stream_sys_t *p_sys = p_stream->p_sys;
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);
p_sys->messagesToSend.push(msg);
@@ -856,7 +863,7 @@ static void msgClose(sout_stream_t *p_stream, std::string destinationId)
sout_stream_sys_t *p_sys = p_stream->p_sys;
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);
p_sys->messagesToSend.push(msg);
@@ -869,7 +876,7 @@ static void msgStatus(sout_stream_t *p_stream)
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());
p_sys->messagesToSend.push(msg);
@@ -884,7 +891,7 @@ static void msgLaunch(sout_stream_t *p_stream)
<< "\"appId\":\"" << APP_ID << "\","
<< "\"requestId\":" << p_stream->p_sys->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());
p_sys->messagesToSend.push(msg);
@@ -904,7 +911,7 @@ static void msgLoad(sout_stream_t *p_stream)
<< "\"contentType\":\"" << p_sys->psz_mime << "\"},"
<< "\"requestId\":" << p_stream->p_sys->i_requestId++ << "}";
- castchannel::CastMessage msg = buildMessage("urn:x-cast:com.google.cast.media",
+ castchannel::CastMessage msg = buildMessage(NAMESPACE_MEDIA,
castchannel::CastMessage_PayloadType_STRING, ss.str(), p_sys->appTransportId);
p_sys->messagesToSend.push(msg);
--
2.5.2
More information about the vlc-devel
mailing list