[vlc-commits] chromecast: reuse the same objects for namespaces

Steve Lhomme git at videolan.org
Wed Dec 23 20:28:23 CET 2015


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Wed Dec 23 12:58:24 2015 +0100| [4921e9a278d6a88f49c8680e8635f751f98a160e] | committer: Jean-Baptiste Kempf

chromecast: reuse the same objects for namespaces

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4921e9a278d6a88f49c8680e8635f751f98a160e
---

 modules/stream_out/chromecast/cast.cpp            |   14 +++++++-------
 modules/stream_out/chromecast/chromecast.h        |   10 ++++++++++
 modules/stream_out/chromecast/chromecast_ctrl.cpp |   14 +++++++-------
 3 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/stream_out/chromecast/cast.cpp
index a7af449..9b1f0ca 100644
--- a/modules/stream_out/chromecast/cast.cpp
+++ b/modules/stream_out/chromecast/cast.cpp
@@ -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"]);
diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index 7c35e33..b496106 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -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
 {
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index b1ebc50..1c4dd35 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -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);



More information about the vlc-commits mailing list