Use size_t more consistently for packet/payload lengths.

See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.

This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.

BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom

Review URL: https://webrtc-codereview.appspot.com/23129004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/test/channel_transport/channel_transport.cc b/webrtc/test/channel_transport/channel_transport.cc
index 4b0a5ae..725a090 100644
--- a/webrtc/test/channel_transport/channel_transport.cc
+++ b/webrtc/test/channel_transport/channel_transport.cc
@@ -50,7 +50,7 @@
 
 void VoiceChannelTransport::IncomingRTPPacket(
     const int8_t* incoming_rtp_packet,
-    const int32_t packet_length,
+    const size_t packet_length,
     const char* /*from_ip*/,
     const uint16_t /*from_port*/) {
   voe_network_->ReceivedRTPPacket(
@@ -59,7 +59,7 @@
 
 void VoiceChannelTransport::IncomingRTCPPacket(
     const int8_t* incoming_rtcp_packet,
-    const int32_t packet_length,
+    const size_t packet_length,
     const char* /*from_ip*/,
     const uint16_t /*from_port*/) {
   voe_network_->ReceivedRTCPPacket(channel_, incoming_rtcp_packet,
@@ -103,7 +103,7 @@
 
 void VideoChannelTransport::IncomingRTPPacket(
     const int8_t* incoming_rtp_packet,
-    const int32_t packet_length,
+    const size_t packet_length,
     const char* /*from_ip*/,
     const uint16_t /*from_port*/) {
   vie_network_->ReceivedRTPPacket(
@@ -112,7 +112,7 @@
 
 void VideoChannelTransport::IncomingRTCPPacket(
     const int8_t* incoming_rtcp_packet,
-    const int32_t packet_length,
+    const size_t packet_length,
     const char* /*from_ip*/,
     const uint16_t /*from_port*/) {
   vie_network_->ReceivedRTCPPacket(channel_, incoming_rtcp_packet,
diff --git a/webrtc/test/channel_transport/include/channel_transport.h b/webrtc/test/channel_transport/include/channel_transport.h
index efe4762..df22012 100644
--- a/webrtc/test/channel_transport/include/channel_transport.h
+++ b/webrtc/test/channel_transport/include/channel_transport.h
@@ -29,12 +29,12 @@
 
   // Start implementation of UdpTransportData.
   virtual void IncomingRTPPacket(const int8_t* incoming_rtp_packet,
-                                 const int32_t packet_length,
+                                 const size_t packet_length,
                                  const char* /*from_ip*/,
                                  const uint16_t /*from_port*/) OVERRIDE;
 
   virtual void IncomingRTCPPacket(const int8_t* incoming_rtcp_packet,
-                                  const int32_t packet_length,
+                                  const size_t packet_length,
                                   const char* /*from_ip*/,
                                   const uint16_t /*from_port*/) OVERRIDE;
   // End implementation of UdpTransportData.
@@ -60,12 +60,12 @@
 
   // Start implementation of UdpTransportData.
   virtual void IncomingRTPPacket(const int8_t* incoming_rtp_packet,
-                         const int32_t packet_length,
+                         const size_t packet_length,
                          const char* /*from_ip*/,
                          const uint16_t /*from_port*/) OVERRIDE;
 
   virtual void IncomingRTCPPacket(const int8_t* incoming_rtcp_packet,
-                          const int32_t packet_length,
+                          const size_t packet_length,
                           const char* /*from_ip*/,
                           const uint16_t /*from_port*/) OVERRIDE;
   // End implementation of UdpTransportData.
diff --git a/webrtc/test/channel_transport/udp_socket2_manager_win.h b/webrtc/test/channel_transport/udp_socket2_manager_win.h
index 956cc03..d3b8aed 100644
--- a/webrtc/test/channel_transport/udp_socket2_manager_win.h
+++ b/webrtc/test/channel_transport/udp_socket2_manager_win.h
@@ -39,7 +39,7 @@
     WSAOVERLAPPED overlapped;
     char buffer[MAX_IO_BUFF_SIZE];
     WSABUF wsabuf;
-    int nTotalBytes;
+    size_t nTotalBytes;
     int nSentBytes;
     int bytes;
     IO_OPERATION ioOperation;
diff --git a/webrtc/test/channel_transport/udp_socket2_win.cc b/webrtc/test/channel_transport/udp_socket2_win.cc
index 98afcb2..1d5234c 100644
--- a/webrtc/test/channel_transport/udp_socket2_win.cc
+++ b/webrtc/test/channel_transport/udp_socket2_win.cc
@@ -14,6 +14,7 @@
 #include <stdlib.h>
 #include <winsock2.h>
 
+#include "webrtc/base/format_macros.h"
 #include "webrtc/system_wrappers/interface/sleep.h"
 #include "webrtc/test/channel_transport/traffic_control_win.h"
 #include "webrtc/test/channel_transport/udp_socket2_manager_win.h"
@@ -349,19 +350,11 @@
     return returnValue;
 }
 
-int32_t UdpSocket2Windows::SendTo(const int8_t* buf, int32_t len,
+int32_t UdpSocket2Windows::SendTo(const int8_t* buf, size_t len,
                                   const SocketAddress& to)
 {
     int32_t retVal = 0;
     int32_t error = 0;
-    if(len < 0)
-    {
-        WEBRTC_TRACE(kTraceError, kTraceTransport, _id,
-                     "UdpSocket2Windows(%d)::SendTo(), len= %d < 0",
-                     (int32_t)this, len);
-        return -1;
-    }
-
     PerIoContext* pIoContext = _mgr->PopIoContext();
     if(pIoContext == 0)
     {
@@ -371,14 +364,15 @@
         return -1;
     }
     // sizeof(pIoContext->buffer) is smaller than the highest number that
-    // can be represented by a int32_t.
-    if(len >= (int32_t) sizeof(pIoContext->buffer))
+    // can be represented by a size_t.
+    if(len >= sizeof(pIoContext->buffer))
     {
         WEBRTC_TRACE(
             kTraceError,
             kTraceTransport,
             _id,
-            "UdpSocket2Windows(%d)::SendTo(), len= %d > buffer_size = %d",
+            "UdpSocket2Windows(%d)::SendTo(), len= %" PRIuS
+            " > buffer_size = %d",
             (int32_t) this,
             len,sizeof(pIoContext->buffer));
         len = sizeof(pIoContext->buffer);
@@ -386,7 +380,7 @@
 
     memcpy(pIoContext->buffer,buf,len);
     pIoContext->wsabuf.buf = pIoContext->buffer;
-    pIoContext->wsabuf.len = len;
+    pIoContext->wsabuf.len = static_cast<ULONG>(len);
     pIoContext->fromLen=sizeof(SocketAddress);
     pIoContext->ioOperation = OP_WRITE;
     pIoContext->nTotalBytes = len;
@@ -424,7 +418,7 @@
     }
     if(retVal == 0 || (retVal == SOCKET_ERROR && error == ERROR_IO_PENDING))
     {
-        return len;
+        return static_cast<int32_t>(len);
     }
     error = _mgr->PushIoContext(pIoContext);
     if(error)
diff --git a/webrtc/test/channel_transport/udp_socket2_win.h b/webrtc/test/channel_transport/udp_socket2_win.h
index 629c9c3..7dec1ed 100644
--- a/webrtc/test/channel_transport/udp_socket2_win.h
+++ b/webrtc/test/channel_transport/udp_socket2_win.h
@@ -56,7 +56,7 @@
     virtual inline bool StartReceiving() OVERRIDE {return StartReceiving(8);}
     virtual bool StopReceiving() OVERRIDE;
 
-    virtual int32_t SendTo(const int8_t* buf, int32_t len,
+    virtual int32_t SendTo(const int8_t* buf, size_t len,
                            const SocketAddress& to) OVERRIDE;
 
     virtual void CloseBlocking() OVERRIDE;
diff --git a/webrtc/test/channel_transport/udp_socket_posix.cc b/webrtc/test/channel_transport/udp_socket_posix.cc
index 355da53..43f75b4 100644
--- a/webrtc/test/channel_transport/udp_socket_posix.cc
+++ b/webrtc/test/channel_transport/udp_socket_posix.cc
@@ -154,7 +154,7 @@
     return false;
 }
 
-int32_t UdpSocketPosix::SendTo(const int8_t* buf, int32_t len,
+int32_t UdpSocketPosix::SendTo(const int8_t* buf, size_t len,
                                const SocketAddress& to)
 {
     int size = sizeof(sockaddr);
diff --git a/webrtc/test/channel_transport/udp_socket_posix.h b/webrtc/test/channel_transport/udp_socket_posix.h
index 8458ca0..c503636 100644
--- a/webrtc/test/channel_transport/udp_socket_posix.h
+++ b/webrtc/test/channel_transport/udp_socket_posix.h
@@ -45,7 +45,7 @@
 
     virtual int32_t SetTOS(const int32_t serviceType) OVERRIDE;
 
-    virtual int32_t SendTo(const int8_t* buf, int32_t len,
+    virtual int32_t SendTo(const int8_t* buf, size_t len,
                            const SocketAddress& to) OVERRIDE;
 
     // Deletes socket in addition to closing it.
diff --git a/webrtc/test/channel_transport/udp_socket_wrapper.h b/webrtc/test/channel_transport/udp_socket_wrapper.h
index 4be4722..d14fcfd 100644
--- a/webrtc/test/channel_transport/udp_socket_wrapper.h
+++ b/webrtc/test/channel_transport/udp_socket_wrapper.h
@@ -38,7 +38,7 @@
 
 typedef void* CallbackObj;
 typedef void(*IncomingSocketCallback)(CallbackObj obj, const int8_t* buf,
-                                      int32_t len, const SocketAddress* from);
+                                      size_t len, const SocketAddress* from);
 
 class UdpSocketWrapper
 {
@@ -79,7 +79,7 @@
     virtual int32_t SetPCP(const int32_t /*pcp*/);
 
     // Send buf of length len to the address specified by to.
-    virtual int32_t SendTo(const int8_t* buf, int32_t len,
+    virtual int32_t SendTo(const int8_t* buf, size_t len,
                            const SocketAddress& to) = 0;
 
     virtual void SetEventToNull();
diff --git a/webrtc/test/channel_transport/udp_transport.h b/webrtc/test/channel_transport/udp_transport.h
index d45326f..a923835 100644
--- a/webrtc/test/channel_transport/udp_transport.h
+++ b/webrtc/test/channel_transport/udp_transport.h
@@ -97,12 +97,12 @@
   virtual ~UdpTransportData()  {};
 
   virtual void IncomingRTPPacket(const int8_t* incomingRtpPacket,
-                                 const int32_t rtpPacketLength,
+                                 const size_t rtpPacketLength,
                                  const char* fromIP,
                                  const uint16_t fromPort) = 0;
 
   virtual void IncomingRTCPPacket(const int8_t* incomingRtcpPacket,
-                                  const int32_t rtcpPacketLength,
+                                  const size_t rtcpPacketLength,
                                   const char* fromIP,
                                   const uint16_t fromPort) = 0;
 };
@@ -283,33 +283,33 @@
     // address as set with InitializeSendSockets(..) is used if ip is NULL.
     // If isRTCP is true the port used will be the RTCP port.
     virtual int32_t SendRaw(const int8_t* data,
-                            uint32_t length,
+                            size_t length,
                             int32_t isRTCP,
                             uint16_t portnr = 0,
                             const char* ip = NULL) = 0;
 
     // Send RTP data with size length to the address specified by to.
     virtual int32_t SendRTPPacketTo(const int8_t* data,
-                                    uint32_t length,
+                                    size_t length,
                                     const SocketAddress& to) = 0;
 
 
     // Send RTCP data with size length to the address specified by to.
     virtual int32_t SendRTCPPacketTo(const int8_t* data,
-                                     uint32_t length,
+                                     size_t length,
                                      const SocketAddress& to) = 0;
 
     // Send RTP data with size length to ip:rtpPort where ip is the ip set by
     // the InitializeSendSockets(..) call.
     virtual int32_t SendRTPPacketTo(const int8_t* data,
-                                    uint32_t length,
+                                    size_t length,
                                     uint16_t rtpPort) = 0;
 
 
     // Send RTCP data with size length to ip:rtcpPort where ip is the ip set by
     // the InitializeSendSockets(..) call.
     virtual int32_t SendRTCPPacketTo(const int8_t* data,
-                                     uint32_t length,
+                                     size_t length,
                                      uint16_t rtcpPort) = 0;
 
     // Set the IP address to which packets are sent to ipaddr.
diff --git a/webrtc/test/channel_transport/udp_transport_impl.cc b/webrtc/test/channel_transport/udp_transport_impl.cc
index c0e897e..c367b2f 100644
--- a/webrtc/test/channel_transport/udp_transport_impl.cc
+++ b/webrtc/test/channel_transport/udp_transport_impl.cc
@@ -1765,7 +1765,7 @@
 }
 
 int32_t UdpTransportImpl::SendRaw(const int8_t *data,
-                                  uint32_t length,
+                                  size_t length,
                                   int32_t isRTCP,
                                   uint16_t portnr,
                                   const char* ip)
@@ -1841,7 +1841,7 @@
 }
 
 int32_t UdpTransportImpl::SendRTPPacketTo(const int8_t* data,
-                                          uint32_t length,
+                                          size_t length,
                                           const SocketAddress& to)
 {
     CriticalSectionScoped cs(_crit);
@@ -1857,7 +1857,7 @@
 }
 
 int32_t UdpTransportImpl::SendRTCPPacketTo(const int8_t* data,
-                                           uint32_t length,
+                                           size_t length,
                                            const SocketAddress& to)
 {
 
@@ -1875,7 +1875,7 @@
 }
 
 int32_t UdpTransportImpl::SendRTPPacketTo(const int8_t* data,
-                                          uint32_t length,
+                                          size_t length,
                                           const uint16_t rtpPort)
 {
     CriticalSectionScoped cs(_crit);
@@ -1903,7 +1903,7 @@
 }
 
 int32_t UdpTransportImpl::SendRTCPPacketTo(const int8_t* data,
-                                           uint32_t length,
+                                           size_t length,
                                            const uint16_t rtcpPort)
 {
     CriticalSectionScoped cs(_crit);
@@ -1931,7 +1931,9 @@
     return -1;
 }
 
-int UdpTransportImpl::SendPacket(int /*channel*/, const void* data, int length)
+int UdpTransportImpl::SendPacket(int /*channel*/,
+                                 const void* data,
+                                 size_t length)
 {
     WEBRTC_TRACE(kTraceStream, kTraceTransport, _id, "%s", __FUNCTION__);
 
@@ -1999,7 +2001,7 @@
 }
 
 int UdpTransportImpl::SendRTCPPacket(int /*channel*/, const void* data,
-                                     int length)
+                                     size_t length)
 {
 
     CriticalSectionScoped cs(_crit);
@@ -2094,7 +2096,7 @@
 
 void UdpTransportImpl::IncomingRTPCallback(CallbackObj obj,
                                            const int8_t* rtpPacket,
-                                           int32_t rtpPacketLength,
+                                           size_t rtpPacketLength,
                                            const SocketAddress* from)
 {
     if (rtpPacket && rtpPacketLength > 0)
@@ -2106,7 +2108,7 @@
 
 void UdpTransportImpl::IncomingRTCPCallback(CallbackObj obj,
                                             const int8_t* rtcpPacket,
-                                            int32_t rtcpPacketLength,
+                                            size_t rtcpPacketLength,
                                             const SocketAddress* from)
 {
     if (rtcpPacket && rtcpPacketLength > 0)
@@ -2118,7 +2120,7 @@
 }
 
 void UdpTransportImpl::IncomingRTPFunction(const int8_t* rtpPacket,
-                                           int32_t rtpPacketLength,
+                                           size_t rtpPacketLength,
                                            const SocketAddress* fromSocket)
 {
     char ipAddress[kIpAddressVersion6Length];
@@ -2181,7 +2183,7 @@
 }
 
 void UdpTransportImpl::IncomingRTCPFunction(const int8_t* rtcpPacket,
-                                            int32_t rtcpPacketLength,
+                                            size_t rtcpPacketLength,
                                             const SocketAddress* fromSocket)
 {
     char ipAddress[kIpAddressVersion6Length];
diff --git a/webrtc/test/channel_transport/udp_transport_impl.h b/webrtc/test/channel_transport/udp_transport_impl.h
index 2b804c3..65ad095 100644
--- a/webrtc/test/channel_transport/udp_transport_impl.h
+++ b/webrtc/test/channel_transport/udp_transport_impl.h
@@ -105,26 +105,28 @@
     virtual bool SourcePortsInitialized() const OVERRIDE;
     virtual bool ReceiveSocketsInitialized() const OVERRIDE;
     virtual int32_t SendRaw(const int8_t* data,
-                            uint32_t length, int32_t isRTCP,
+                            size_t length, int32_t isRTCP,
                             uint16_t portnr = 0,
                             const char* ip = NULL) OVERRIDE;
     virtual int32_t SendRTPPacketTo(const int8_t *data,
-                                    uint32_t length,
+                                    size_t length,
                                     const SocketAddress& to) OVERRIDE;
     virtual int32_t SendRTCPPacketTo(const int8_t *data,
-                                     uint32_t length,
+                                     size_t length,
                                      const SocketAddress& to) OVERRIDE;
     virtual int32_t SendRTPPacketTo(const int8_t *data,
-                                    uint32_t length,
+                                    size_t length,
                                     uint16_t rtpPort) OVERRIDE;
     virtual int32_t SendRTCPPacketTo(const int8_t *data,
-                                     uint32_t length,
+                                     size_t length,
                                      uint16_t rtcpPort) OVERRIDE;
     // Transport functions
-    virtual int SendPacket(int channel, const void* data, int length) OVERRIDE;
+    virtual int SendPacket(int channel,
+                           const void* data,
+                           size_t length) OVERRIDE;
     virtual int SendRTCPPacket(int channel,
                                const void* data,
-                               int length) OVERRIDE;
+                               size_t length) OVERRIDE;
 
     // UdpTransport functions continue.
     virtual int32_t SetSendIP(const char* ipaddr) OVERRIDE;
@@ -144,11 +146,11 @@
     // UdpSocketWrapper.
     static void IncomingRTPCallback(CallbackObj obj,
                                     const int8_t* rtpPacket,
-                                    int32_t rtpPacketLength,
+                                    size_t rtpPacketLength,
                                     const SocketAddress* from);
     static void IncomingRTCPCallback(CallbackObj obj,
                                      const int8_t* rtcpPacket,
-                                     int32_t rtcpPacketLength,
+                                     size_t rtcpPacketLength,
                                      const SocketAddress* from);
 
     void CloseSendSockets();
@@ -169,10 +171,10 @@
     ErrorCode BindRTCPSendSocket();
 
     void IncomingRTPFunction(const int8_t* rtpPacket,
-                             int32_t rtpPacketLength,
+                             size_t rtpPacketLength,
                              const SocketAddress* from);
     void IncomingRTCPFunction(const int8_t* rtcpPacket,
-                              int32_t rtcpPacketLength,
+                              size_t rtcpPacketLength,
                               const SocketAddress* from);
 
     bool FilterIPAddress(const SocketAddress* fromAddress);
diff --git a/webrtc/test/channel_transport/udp_transport_unittest.cc b/webrtc/test/channel_transport/udp_transport_unittest.cc
index 5ccc9ef..862ebf9 100644
--- a/webrtc/test/channel_transport/udp_transport_unittest.cc
+++ b/webrtc/test/channel_transport/udp_transport_unittest.cc
@@ -36,7 +36,7 @@
                                 const int8_t*,
                                 int32_t));
   MOCK_METHOD1(SetTOS, int32_t(int32_t));
-  MOCK_METHOD3(SendTo, int32_t(const int8_t*, int32_t, const SocketAddress&));
+  MOCK_METHOD3(SendTo, int32_t(const int8_t*, size_t, const SocketAddress&));
   MOCK_METHOD8(SetQos, bool(int32_t, int32_t,
                             int32_t, int32_t,
                             int32_t, int32_t,
diff --git a/webrtc/test/configurable_frame_size_encoder.cc b/webrtc/test/configurable_frame_size_encoder.cc
index d3ed784..f25f443 100644
--- a/webrtc/test/configurable_frame_size_encoder.cc
+++ b/webrtc/test/configurable_frame_size_encoder.cc
@@ -21,7 +21,7 @@
 namespace test {
 
 ConfigurableFrameSizeEncoder::ConfigurableFrameSizeEncoder(
-    uint32_t max_frame_size)
+    size_t max_frame_size)
     : callback_(NULL),
       max_frame_size_(max_frame_size),
       current_frame_size_(max_frame_size),
@@ -34,7 +34,7 @@
 int32_t ConfigurableFrameSizeEncoder::InitEncode(
     const VideoCodec* codec_settings,
     int32_t number_of_cores,
-    uint32_t max_payload_size) {
+    size_t max_payload_size) {
   return WEBRTC_VIDEO_CODEC_OK;
 }
 
@@ -87,7 +87,7 @@
   return WEBRTC_VIDEO_CODEC_OK;
 }
 
-int32_t ConfigurableFrameSizeEncoder::SetFrameSize(uint32_t size) {
+int32_t ConfigurableFrameSizeEncoder::SetFrameSize(size_t size) {
   assert(size <= max_frame_size_);
   current_frame_size_ = size;
   return WEBRTC_VIDEO_CODEC_OK;
diff --git a/webrtc/test/configurable_frame_size_encoder.h b/webrtc/test/configurable_frame_size_encoder.h
index 4120bc6..43c4b29 100644
--- a/webrtc/test/configurable_frame_size_encoder.h
+++ b/webrtc/test/configurable_frame_size_encoder.h
@@ -21,12 +21,12 @@
 
 class ConfigurableFrameSizeEncoder : public VideoEncoder {
  public:
-  explicit ConfigurableFrameSizeEncoder(uint32_t max_frame_size);
+  explicit ConfigurableFrameSizeEncoder(size_t max_frame_size);
   virtual ~ConfigurableFrameSizeEncoder();
 
   virtual int32_t InitEncode(const VideoCodec* codec_settings,
                              int32_t number_of_cores,
-                             uint32_t max_payload_size) OVERRIDE;
+                             size_t max_payload_size) OVERRIDE;
 
   virtual int32_t Encode(const I420VideoFrame& input_image,
                          const CodecSpecificInfo* codec_specific_info,
@@ -46,12 +46,12 @@
 
   virtual int32_t CodecConfigParameters(uint8_t* buffer, int32_t size) OVERRIDE;
 
-  int32_t SetFrameSize(uint32_t size);
+  int32_t SetFrameSize(size_t size);
 
  private:
   EncodedImageCallback* callback_;
-  const uint32_t max_frame_size_;
-  uint32_t current_frame_size_;
+  const size_t max_frame_size_;
+  size_t current_frame_size_;
   scoped_ptr<uint8_t[]> buffer_;
 };
 
diff --git a/webrtc/test/fake_encoder.cc b/webrtc/test/fake_encoder.cc
index 41d0ea3..d0b6402 100644
--- a/webrtc/test/fake_encoder.cc
+++ b/webrtc/test/fake_encoder.cc
@@ -39,7 +39,7 @@
 
 int32_t FakeEncoder::InitEncode(const VideoCodec* config,
                                 int32_t number_of_cores,
-                                uint32_t max_payload_size) {
+                                size_t max_payload_size) {
   config_ = *config;
   target_bitrate_kbps_ = config_.startBitrate;
   return 0;
@@ -50,7 +50,7 @@
     const CodecSpecificInfo* codec_specific_info,
     const std::vector<VideoFrameType>* frame_types) {
   assert(config_.maxFramerate > 0);
-  int time_since_last_encode_ms = 1000 / config_.maxFramerate;
+  int64_t time_since_last_encode_ms = 1000 / config_.maxFramerate;
   int64_t time_now_ms = clock_->TimeInMilliseconds();
   const bool first_encode = last_encode_time_ms_ == 0;
   if (!first_encode) {
@@ -59,36 +59,38 @@
     time_since_last_encode_ms = time_now_ms - last_encode_time_ms_;
   }
 
-  int bits_available = target_bitrate_kbps_ * time_since_last_encode_ms;
-  int min_bits =
-      config_.simulcastStream[0].minBitrate * time_since_last_encode_ms;
+  size_t bits_available =
+      static_cast<size_t>(target_bitrate_kbps_ * time_since_last_encode_ms);
+  size_t min_bits = static_cast<size_t>(
+      config_.simulcastStream[0].minBitrate * time_since_last_encode_ms);
   if (bits_available < min_bits)
     bits_available = min_bits;
-  int max_bits = max_target_bitrate_kbps_ * time_since_last_encode_ms;
+  size_t max_bits =
+      static_cast<size_t>(max_target_bitrate_kbps_ * time_since_last_encode_ms);
   if (max_bits > 0 && max_bits < bits_available)
     bits_available = max_bits;
   last_encode_time_ms_ = time_now_ms;
 
   assert(config_.numberOfSimulcastStreams > 0);
-  for (int i = 0; i < config_.numberOfSimulcastStreams; ++i) {
+  for (unsigned char i = 0; i < config_.numberOfSimulcastStreams; ++i) {
     CodecSpecificInfo specifics;
     memset(&specifics, 0, sizeof(specifics));
     specifics.codecType = kVideoCodecGeneric;
     specifics.codecSpecific.generic.simulcast_idx = i;
-    int min_stream_bits =
-        config_.simulcastStream[i].minBitrate * time_since_last_encode_ms;
-    int max_stream_bits =
-        config_.simulcastStream[i].maxBitrate * time_since_last_encode_ms;
-    int stream_bits = (bits_available > max_stream_bits) ? max_stream_bits :
+    size_t min_stream_bits = static_cast<size_t>(
+        config_.simulcastStream[i].minBitrate * time_since_last_encode_ms);
+    size_t max_stream_bits = static_cast<size_t>(
+        config_.simulcastStream[i].maxBitrate * time_since_last_encode_ms);
+    size_t stream_bits = (bits_available > max_stream_bits) ? max_stream_bits :
         bits_available;
-    int stream_bytes = (stream_bits + 7) / 8;
+    size_t stream_bytes = (stream_bits + 7) / 8;
     if (first_encode) {
       // The first frame is a key frame and should be larger.
       // TODO(holmer): The FakeEncoder should store the bits_available between
       // encodes so that it can compensate for oversized frames.
       stream_bytes *= 10;
     }
-    if (static_cast<size_t>(stream_bytes) > sizeof(encoded_buffer_))
+    if (stream_bytes > sizeof(encoded_buffer_))
       stream_bytes = sizeof(encoded_buffer_);
 
     EncodedImage encoded(
@@ -104,7 +106,7 @@
     assert(callback_ != NULL);
     if (callback_->Encoded(encoded, &specifics, NULL) != 0)
       return -1;
-    bits_available -= encoded._length * 8;
+    bits_available -= std::min(encoded._length * 8, bits_available);
   }
   return 0;
 }
@@ -155,9 +157,9 @@
     fragmentation.fragmentationOffset[2] = kSpsSize + kPpsSize;
     fragmentation.fragmentationLength[2] =
         encoded_image._length - (kSpsSize + kPpsSize);
-    const uint8_t kSpsNalHeader = 0x37;
-    const uint8_t kPpsNalHeader = 0x38;
-    const uint8_t kIdrNalHeader = 0x15;
+    const size_t kSpsNalHeader = 0x37;
+    const size_t kPpsNalHeader = 0x38;
+    const size_t kIdrNalHeader = 0x15;
     encoded_image._buffer[fragmentation.fragmentationOffset[0]] = kSpsNalHeader;
     encoded_image._buffer[fragmentation.fragmentationOffset[1]] = kPpsNalHeader;
     encoded_image._buffer[fragmentation.fragmentationOffset[2]] = kIdrNalHeader;
@@ -166,7 +168,7 @@
     fragmentation.VerifyAndAllocateFragmentationHeader(kNumSlices);
     fragmentation.fragmentationOffset[0] = 0;
     fragmentation.fragmentationLength[0] = encoded_image._length;
-    const uint8_t kNalHeader = 0x11;
+    const size_t kNalHeader = 0x11;
     encoded_image._buffer[fragmentation.fragmentationOffset[0]] = kNalHeader;
   }
   uint8_t value = 0;
diff --git a/webrtc/test/fake_encoder.h b/webrtc/test/fake_encoder.h
index 01b83f0..b77cb3e 100644
--- a/webrtc/test/fake_encoder.h
+++ b/webrtc/test/fake_encoder.h
@@ -30,7 +30,7 @@
 
   virtual int32_t InitEncode(const VideoCodec* config,
                              int32_t number_of_cores,
-                             uint32_t max_payload_size) OVERRIDE;
+                             size_t max_payload_size) OVERRIDE;
   virtual int32_t Encode(
      const I420VideoFrame& input_image,
      const CodecSpecificInfo* codec_specific_info,
diff --git a/webrtc/test/mock_transport.h b/webrtc/test/mock_transport.h
index 388ee92..5b1cb8d 100644
--- a/webrtc/test/mock_transport.h
+++ b/webrtc/test/mock_transport.h
@@ -19,9 +19,9 @@
 class MockTransport : public webrtc::Transport {
  public:
   MOCK_METHOD3(SendPacket,
-      int(int channel, const void* data, int len));
+      int(int channel, const void* data, size_t len));
   MOCK_METHOD3(SendRTCPPacket,
-      int(int channel, const void* data, int len));
+      int(int channel, const void* data, size_t len));
 };
 }  // namespace webrtc
 #endif  // WEBRTC_TEST_MOCK_TRANSPORT_H_
diff --git a/webrtc/test/rtcp_packet_parser.cc b/webrtc/test/rtcp_packet_parser.cc
index 558bee3..391be85 100644
--- a/webrtc/test/rtcp_packet_parser.cc
+++ b/webrtc/test/rtcp_packet_parser.cc
@@ -17,7 +17,7 @@
 
 RtcpPacketParser::~RtcpPacketParser() {}
 
-void RtcpPacketParser::Parse(const void *data, int len) {
+void RtcpPacketParser::Parse(const void *data, size_t len) {
   const uint8_t* packet = static_cast<const uint8_t*>(data);
   RTCPUtility::RTCPParserV2 parser(packet, len, true);
   for (RTCPUtility::RTCPPacketTypes type = parser.Begin();
diff --git a/webrtc/test/rtcp_packet_parser.h b/webrtc/test/rtcp_packet_parser.h
index f7d36ba..cc890b4 100644
--- a/webrtc/test/rtcp_packet_parser.h
+++ b/webrtc/test/rtcp_packet_parser.h
@@ -631,7 +631,7 @@
   RtcpPacketParser();
   ~RtcpPacketParser();
 
-  void Parse(const void *packet, int packet_len);
+  void Parse(const void *packet, size_t packet_len);
 
   SenderReport* sender_report() { return &sender_report_; }
   ReceiverReport* receiver_report() { return &receiver_report_; }
diff --git a/webrtc/test/testsupport/packet_reader.cc b/webrtc/test/testsupport/packet_reader.cc
index 54552bd..e27ec22 100644
--- a/webrtc/test/testsupport/packet_reader.cc
+++ b/webrtc/test/testsupport/packet_reader.cc
@@ -12,6 +12,7 @@
 
 #include <assert.h>
 #include <stdio.h>
+#include <algorithm>
 
 namespace webrtc {
 namespace test {
@@ -22,10 +23,9 @@
 PacketReader::~PacketReader() {}
 
 void PacketReader::InitializeReading(uint8_t* data,
-                                     int data_length_in_bytes,
-                                     int packet_size_in_bytes) {
+                                     size_t data_length_in_bytes,
+                                     size_t packet_size_in_bytes) {
   assert(data);
-  assert(data_length_in_bytes >= 0);
   assert(packet_size_in_bytes > 0);
   data_ = data;
   data_length_ = data_length_in_bytes;
@@ -40,16 +40,9 @@
     return -1;
   }
   *packet_pointer = data_ + currentIndex_;
-  // Check if we're about to read the last packet:
-  if (data_length_ - currentIndex_ <= packet_size_) {
-    int size = data_length_ - currentIndex_;
-    currentIndex_ = data_length_;
-    assert(size >= 0);
-    return size;
-  }
-  currentIndex_ += packet_size_;
-  assert(packet_size_ >= 0);
-  return packet_size_;
+  size_t old_index = currentIndex_;
+  currentIndex_ = std::min(currentIndex_ + packet_size_, data_length_);
+  return static_cast<int>(currentIndex_ - old_index);
 }
 
 }  // namespace test
diff --git a/webrtc/test/testsupport/packet_reader.h b/webrtc/test/testsupport/packet_reader.h
index e84ecd9..b58db4d 100644
--- a/webrtc/test/testsupport/packet_reader.h
+++ b/webrtc/test/testsupport/packet_reader.h
@@ -11,6 +11,7 @@
 #ifndef WEBRTC_TEST_TESTSUPPORT_PACKET_READER_H_
 #define WEBRTC_TEST_TESTSUPPORT_PACKET_READER_H_
 
+#include <cstddef>
 #include "webrtc/typedefs.h"
 
 namespace webrtc {
@@ -24,12 +25,12 @@
 
   // Inizializes a new reading operation. Must be done before invoking the
   // NextPacket method.
-  // * data_length_in_bytes is the length of the data byte array. Must be >= 0.
+  // * data_length_in_bytes is the length of the data byte array.
   //   0 length will result in no packets are read.
   // * packet_size_in_bytes is the number of bytes to read in each NextPacket
   //   method call. Must be > 0
-  virtual void InitializeReading(uint8_t* data, int data_length_in_bytes,
-                                 int packet_size_in_bytes);
+  virtual void InitializeReading(uint8_t* data, size_t data_length_in_bytes,
+                                 size_t packet_size_in_bytes);
 
   // Moves the supplied pointer to the beginning of the next packet.
   // Returns:
@@ -41,9 +42,9 @@
 
  private:
   uint8_t* data_;
-  int data_length_;
-  int packet_size_;
-  int currentIndex_;
+  size_t data_length_;
+  size_t packet_size_;
+  size_t currentIndex_;
   bool initialized_;
 };
 
diff --git a/webrtc/test/testsupport/packet_reader_unittest.cc b/webrtc/test/testsupport/packet_reader_unittest.cc
index 83cde69..2679be4 100644
--- a/webrtc/test/testsupport/packet_reader_unittest.cc
+++ b/webrtc/test/testsupport/packet_reader_unittest.cc
@@ -26,11 +26,11 @@
   void TearDown() {
     delete reader_;
   }
-  void VerifyPacketData(int expected_length,
+  void VerifyPacketData(size_t expected_length,
                         int actual_length,
                         uint8_t* original_data_pointer,
                         uint8_t* new_data_pointer) {
-    EXPECT_EQ(expected_length, actual_length);
+    EXPECT_EQ(static_cast<int>(expected_length), actual_length);
     EXPECT_EQ(*original_data_pointer, *new_data_pointer);
     EXPECT_EQ(0, memcmp(original_data_pointer, new_data_pointer,
                         actual_length));
@@ -82,7 +82,7 @@
   // Reading another one shall result in 0 bytes:
   length_to_read = reader_->NextPacket(&data_pointer);
   EXPECT_EQ(0, length_to_read);
-  EXPECT_EQ(kPacketSizeInBytes, data_pointer - data);
+  EXPECT_EQ(kPacketSizeInBytes, static_cast<size_t>(data_pointer - data));
 }
 
 // Test with data length that will result in 3 packets
@@ -105,7 +105,8 @@
   // Reading another one shall result in 0 bytes:
   length_to_read = reader_->NextPacket(&packet_data_pointer_);
   EXPECT_EQ(0, length_to_read);
-  EXPECT_EQ(kPacketDataLength, packet_data_pointer_ - packet_data_);
+  EXPECT_EQ(kPacketDataLength,
+            static_cast<size_t>(packet_data_pointer_ - packet_data_));
 }
 
 // Test with empty data.
diff --git a/webrtc/test/testsupport/unittest_utils.h b/webrtc/test/testsupport/unittest_utils.h
index bb244a4..ba6db98 100644
--- a/webrtc/test/testsupport/unittest_utils.h
+++ b/webrtc/test/testsupport/unittest_utils.h
@@ -14,8 +14,8 @@
 namespace webrtc {
 namespace test {
 
-const int kPacketSizeInBytes = 1500;
-const int kPacketDataLength = kPacketSizeInBytes * 2 + 1;
+const size_t kPacketSizeInBytes = 1500;
+const size_t kPacketDataLength = kPacketSizeInBytes * 2 + 1;
 const int kPacketDataNumberOfPackets = 3;
 
 // A base test fixture for packet related tests. Contains