[vlc-commits] chromecast_ctrl: send messages right away
Steve Lhomme
git at videolan.org
Fri Jan 8 10:47:21 CET 2016
vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Tue Jan 5 11:21:00 2016 +0100| [7f5755211296d5aee5c24d901a248904d59877c4] | committer: Jean-Baptiste Kempf
chromecast_ctrl: send messages right away
The Chromecast protocol is not a client server, all requests don't get an
answer and we can receive unexpected broadcasts.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7f5755211296d5aee5c24d901a248904d59877c4
---
modules/stream_out/chromecast/cast.cpp | 3 -
modules/stream_out/chromecast/chromecast.h | 7 +--
modules/stream_out/chromecast/chromecast_ctrl.cpp | 65 +++++----------------
3 files changed, 17 insertions(+), 58 deletions(-)
diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/stream_out/chromecast/cast.cpp
index 29b02bb..052b685 100644
--- a/modules/stream_out/chromecast/cast.cpp
+++ b/modules/stream_out/chromecast/cast.cpp
@@ -286,8 +286,6 @@ static void Close(vlc_object_t *p_this)
// ft
case CHROMECAST_AUTHENTICATED:
p_sys->p_intf->msgReceiverClose(DEFAULT_CHOMECAST_RECEIVER);
- // Send the just added close messages.
- p_sys->p_intf->sendMessages();
// ft
default:
break;
@@ -328,7 +326,6 @@ static void* chromecastThread(void* p_data)
sout_stream_sys_t* p_sys = p_stream->p_sys;
p_sys->p_intf->msgAuth();
- p_sys->p_intf->sendMessages();
vlc_restorecancel(canc);
while (1)
diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index d5ef655..f39c7d2 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -34,8 +34,6 @@
#include <vlc_sout.h>
#include <vlc_tls.h>
-#include <queue>
-
#include "cast_channel.pb.h"
#define PACKET_HEADER_LEN 4
@@ -77,7 +75,6 @@ struct intf_sys_t
void msgReceiverClose(std::string destinationId);
void handleMessages();
- int sendMessages();
connection_status getConnectionStatus() const
{
@@ -108,12 +105,10 @@ struct intf_sys_t
void msgPlayerLoad();
- std::queue<castchannel::CastMessage> messagesToSend;
-
void processMessage(const castchannel::CastMessage &msg);
private:
- int sendMessage(castchannel::CastMessage &msg);
+ int sendMessage(const castchannel::CastMessage &msg);
void buildMessage(const std::string & namespace_,
const std::string & payload,
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 6110cd0..89a7958 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -88,7 +88,7 @@ void intf_sys_t::buildMessage(const std::string & namespace_,
else // CastMessage_PayloadType_BINARY
msg.set_payload_binary(payload);
- messagesToSend.push(msg);
+ sendMessage(msg);
}
intf_sys_t::intf_sys_t(sout_stream_t * const p_this)
@@ -529,46 +529,29 @@ void intf_sys_t::msgPlayerLoad()
/**
* @brief Send a message to the Chromecast
* @param msg the CastMessage to send
- * @return the number of bytes sent or -1 on error
+ * @return vlc error code
*/
-int intf_sys_t::sendMessage(castchannel::CastMessage &msg)
+int intf_sys_t::sendMessage(const castchannel::CastMessage &msg)
{
- uint32_t i_size = msg.ByteSize();
- uint32_t i_sizeNetwork = hton32(i_size);
-
- char *p_data = new(std::nothrow) char[PACKET_HEADER_LEN + i_size];
+ int i_size = msg.ByteSize();
+ uint8_t *p_data = new(std::nothrow) uint8_t[PACKET_HEADER_LEN + i_size];
if (p_data == NULL)
- return -1;
+ return VLC_ENOMEM;
- memcpy(p_data, &i_sizeNetwork, PACKET_HEADER_LEN);
- msg.SerializeWithCachedSizesToArray((uint8_t *)(p_data + PACKET_HEADER_LEN));
+#ifndef NDEBUG
+ msg_Dbg(p_stream, "sendMessage: %s->%s %s", msg.namespace_().c_str(), msg.destination_id().c_str(), msg.payload_utf8().c_str());
+#endif
+ SetDWBE(p_data, i_size);
+ msg.SerializeWithCachedSizesToArray(p_data + PACKET_HEADER_LEN);
+
+ vlc_mutex_locker locker(&lock);
int i_ret = tls_Send(p_tls, p_data, PACKET_HEADER_LEN + i_size);
delete[] p_data;
+ if (i_ret == PACKET_HEADER_LEN + i_size)
+ return VLC_SUCCESS;
- return i_ret;
-}
-
-
-/**
- * @brief Send all the messages in the pending queue to the Chromecast
- * @param msg the CastMessage to send
- * @return the number of bytes sent or -1 on error
- */
-int intf_sys_t::sendMessages()
-{
- int i_ret = 0;
- while (!messagesToSend.empty())
- {
- unsigned i_retSend = sendMessage(messagesToSend.front());
- if (i_retSend <= 0)
- return i_retSend;
-
- messagesToSend.pop();
- i_ret += i_retSend;
- }
-
- return i_ret;
+ return VLC_EGENERIC;
}
void intf_sys_t::handleMessages()
@@ -615,21 +598,5 @@ void intf_sys_t::handleMessages()
processMessage(msg);
}
- // Send the answer messages if there is any.
- if (!messagesToSend.empty())
- {
- i_ret = sendMessages();
-#if defined(_WIN32)
- if ((i_ret < 0 && WSAGetLastError() != WSAEWOULDBLOCK) || (i_ret == 0))
-#else
- if ((i_ret < 0 && errno != EAGAIN) || i_ret == 0)
-#endif
- {
- msg_Err(p_stream, "The connection to the Chromecast died (sending).");
- vlc_mutex_locker locker(&lock);
- setConnectionStatus(CHROMECAST_CONNECTION_DEAD);
- }
- }
-
vlc_restorecancel(canc);
}
More information about the vlc-commits
mailing list