[vlc-commits] chromecast: make sure we send all the message data

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


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

chromecast: make sure we send all the message data

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

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

 modules/stream_out/chromecast/chromecast_ctrl.cpp |   69 ++++++++++-----------
 1 file changed, 34 insertions(+), 35 deletions(-)

diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 8a1b968..70ce9bc 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -116,7 +116,7 @@ intf_sys_t::~intf_sys_t()
 // Use here only C linkage and POD types as this function is a cancelation point.
 extern "C" int recvPacket(sout_stream_t *p_stream, bool &b_msgReceived,
                           uint32_t &i_payloadSize, int i_sock_fd, vlc_tls_t *p_tls,
-                          unsigned *pi_received, char *p_data, bool *pb_pingTimeout,
+                          unsigned *pi_received, uint8_t *p_data, bool *pb_pingTimeout,
                           int *pi_wait_delay, int *pi_wait_retries)
 {
     struct pollfd ufd[1];
@@ -161,47 +161,32 @@ extern "C" int recvPacket(sout_stream_t *p_stream, bool &b_msgReceived,
      * +------------------------------------+------------------------------+
      * | Payload size (uint32_t big endian) |         Payload data         |
      * +------------------------------------+------------------------------+ */
-    if (*pi_received < PACKET_HEADER_LEN)
+    while (*pi_received < PACKET_HEADER_LEN)
     {
         // We receive the header.
-        i_ret = tls_Recv(p_tls, p_data, PACKET_HEADER_LEN - *pi_received);
+        i_ret = tls_Recv(p_tls, p_data + *pi_received, PACKET_HEADER_LEN - *pi_received);
         if (i_ret <= 0)
             return i_ret;
         *pi_received += i_ret;
     }
-    else
-    {
-        // We receive the payload.
-
-        // Get the size of the payload
-        memcpy(&i_payloadSize, p_data, PACKET_HEADER_LEN);
-        i_payloadSize = hton32(i_payloadSize);
-        const uint32_t i_maxPayloadSize = PACKET_MAX_LEN - PACKET_HEADER_LEN;
-
-        if (i_payloadSize > i_maxPayloadSize)
-        {
-            // Error case: the packet sent by the Chromecast is too long: we drop it.
-            msg_Err(p_stream, "Packet too long: droping its data");
 
-            uint32_t i_size = i_payloadSize - (*pi_received - PACKET_HEADER_LEN);
-            if (i_size > i_maxPayloadSize)
-                i_size = i_maxPayloadSize;
+    // We receive the payload.
 
-            i_ret = tls_Recv(p_tls, p_data + PACKET_HEADER_LEN, i_size);
-            if (i_ret <= 0)
-                return i_ret;
-            *pi_received += i_ret;
+    // Get the size of the payload
+    memcpy(&i_payloadSize, p_data, PACKET_HEADER_LEN);
+    i_payloadSize = hton32(i_payloadSize);
+    const uint32_t i_maxPayloadSize = PACKET_MAX_LEN - PACKET_HEADER_LEN;
 
-            if (*pi_received < i_payloadSize + PACKET_HEADER_LEN)
-                return i_ret;
+    if (i_payloadSize > i_maxPayloadSize)
+    {
+        // Error case: the packet sent by the Chromecast is too long: we drop it.
+        msg_Err(p_stream, "Packet too long: droping its data");
 
-            *pi_received = 0;
-            return -1;
-        }
+        uint32_t i_size = i_payloadSize - (*pi_received - PACKET_HEADER_LEN);
+        if (i_size > i_maxPayloadSize)
+            i_size = i_maxPayloadSize;
 
-        // Normal case
-        i_ret = tls_Recv(p_tls, p_data + *pi_received,
-                         i_payloadSize - (*pi_received - PACKET_HEADER_LEN));
+        i_ret = tls_Recv(p_tls, p_data + PACKET_HEADER_LEN, i_size);
         if (i_ret <= 0)
             return i_ret;
         *pi_received += i_ret;
@@ -209,12 +194,26 @@ extern "C" int recvPacket(sout_stream_t *p_stream, bool &b_msgReceived,
         if (*pi_received < i_payloadSize + PACKET_HEADER_LEN)
             return i_ret;
 
-        assert(*pi_received == i_payloadSize + PACKET_HEADER_LEN);
         *pi_received = 0;
-        b_msgReceived = true;
-        return i_ret;
+        return -1;
     }
 
+    // Normal case
+    i_ret = tls_Recv(p_tls, p_data + *pi_received,
+                     i_payloadSize - (*pi_received - PACKET_HEADER_LEN));
+    if (i_ret <= 0)
+        return i_ret;
+    *pi_received += i_ret;
+
+    if (*pi_received < i_payloadSize + PACKET_HEADER_LEN)
+        return i_ret;
+
+    assert(*pi_received == i_payloadSize + PACKET_HEADER_LEN);
+    *pi_received = 0;
+    b_msgReceived = true;
+    return i_ret;
+
+
     return i_ret;
 }
 
@@ -509,7 +508,7 @@ int intf_sys_t::sendMessages()
 void intf_sys_t::handleMessages()
 {
     unsigned i_received = 0;
-    char p_packet[PACKET_MAX_LEN];
+    uint8_t p_packet[PACKET_MAX_LEN];
     bool b_pingTimeout = false;
 
     int i_waitdelay = PING_WAIT_TIME;



More information about the vlc-commits mailing list