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/modules/rtp_rtcp/interface/fec_receiver.h b/webrtc/modules/rtp_rtcp/interface/fec_receiver.h
index e2ef4b1..da54bf6 100644
--- a/webrtc/modules/rtp_rtcp/interface/fec_receiver.h
+++ b/webrtc/modules/rtp_rtcp/interface/fec_receiver.h
@@ -24,7 +24,7 @@
 
   virtual int32_t AddReceivedRedPacket(const RTPHeader& rtp_header,
                                        const uint8_t* incoming_rtp_packet,
-                                       int packet_length,
+                                       size_t packet_length,
                                        uint8_t ulpfec_payload_type) = 0;
 
   virtual int32_t ProcessReceivedFec() = 0;
diff --git a/webrtc/modules/rtp_rtcp/interface/receive_statistics.h b/webrtc/modules/rtp_rtcp/interface/receive_statistics.h
index 6f2ea4f..ae1fbb6 100644
--- a/webrtc/modules/rtp_rtcp/interface/receive_statistics.h
+++ b/webrtc/modules/rtp_rtcp/interface/receive_statistics.h
@@ -26,7 +26,7 @@
   virtual ~StreamStatistician();
 
   virtual bool GetStatistics(RtcpStatistics* statistics, bool reset) = 0;
-  virtual void GetDataCounters(uint32_t* bytes_received,
+  virtual void GetDataCounters(size_t* bytes_received,
                                uint32_t* packets_received) const = 0;
   virtual uint32_t BitrateReceived() const = 0;
 
diff --git a/webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h b/webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h
index 327ea16..bbdac67 100644
--- a/webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h
+++ b/webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h
@@ -83,7 +83,7 @@
 
   bool RestoreOriginalPacket(uint8_t** restored_packet,
                              const uint8_t* packet,
-                             int* packet_length,
+                             size_t* packet_length,
                              uint32_t original_ssrc,
                              const RTPHeader& header) const;
 
diff --git a/webrtc/modules/rtp_rtcp/interface/rtp_receiver.h b/webrtc/modules/rtp_rtcp/interface/rtp_receiver.h
index 00e5e5d..6283566 100644
--- a/webrtc/modules/rtp_rtcp/interface/rtp_receiver.h
+++ b/webrtc/modules/rtp_rtcp/interface/rtp_receiver.h
@@ -72,7 +72,7 @@
   // detected and acted upon.
   virtual bool IncomingRtpPacket(const RTPHeader& rtp_header,
                                  const uint8_t* payload,
-                                 int payload_length,
+                                 size_t payload_length,
                                  PayloadUnion payload_specific,
                                  bool in_order) = 0;
 
diff --git a/webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h b/webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h
index ca686c0..c1250b9 100644
--- a/webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h
+++ b/webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h
@@ -83,7 +83,7 @@
    ***************************************************************************/
 
     virtual int32_t IncomingRtcpPacket(const uint8_t* incoming_packet,
-                                       uint16_t incoming_packet_length) = 0;
+                                       size_t incoming_packet_length) = 0;
 
     virtual void SetRemoteSSRC(const uint32_t ssrc) = 0;
 
@@ -328,7 +328,7 @@
         const uint32_t timeStamp,
         int64_t capture_time_ms,
         const uint8_t* payloadData,
-        const uint32_t payloadSize,
+        const size_t payloadSize,
         const RTPFragmentationHeader* fragmentation = NULL,
         const RTPVideoHeader* rtpVideoHdr = NULL) = 0;
 
@@ -337,7 +337,7 @@
                                   int64_t capture_time_ms,
                                   bool retransmission) = 0;
 
-    virtual int TimeToSendPadding(int bytes) = 0;
+    virtual size_t TimeToSendPadding(size_t bytes) = 0;
 
     virtual bool GetSendSideDelay(int* avg_send_delay_ms,
                                   int* max_send_delay_ms) const = 0;
@@ -465,7 +465,7 @@
     *   return -1 on failure else 0
     */
     virtual int32_t DataCountersRTP(
-        uint32_t* bytesSent,
+        size_t* bytesSent,
         uint32_t* packetsSent) const = 0;
     /*
     *   Get received RTCP sender info
diff --git a/webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h b/webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h
index dc51467..e94be57 100644
--- a/webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h
+++ b/webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h
@@ -143,7 +143,7 @@
                                   // instead of padding.
 };
 
-const int kRtxHeaderSize = 2;
+const size_t kRtxHeaderSize = 2;
 
 struct RTCPSenderInfo
 {
@@ -220,11 +220,11 @@
 
     virtual int32_t OnReceivedPayloadData(
         const uint8_t* payloadData,
-        const uint16_t payloadSize,
+        const size_t payloadSize,
         const WebRtcRTPHeader* rtpHeader) = 0;
 
     virtual bool OnRecoveredPacket(const uint8_t* packet,
-                                   int packet_length) = 0;
+                                   size_t packet_length) = 0;
 };
 
 class RtpFeedback
@@ -334,13 +334,13 @@
 
   virtual int32_t OnReceivedPayloadData(
       const uint8_t* payloadData,
-      const uint16_t payloadSize,
+      const size_t payloadSize,
       const WebRtcRTPHeader* rtpHeader) OVERRIDE {
     return 0;
   }
 
   virtual bool OnRecoveredPacket(const uint8_t* packet,
-                                 int packet_length) OVERRIDE {
+                                 size_t packet_length) OVERRIDE {
     return true;
   }
 };
diff --git a/webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h b/webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h
index 584b9ad..7880660 100644
--- a/webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h
+++ b/webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h
@@ -23,11 +23,11 @@
  public:
   MOCK_METHOD3(OnReceivedPayloadData,
                int32_t(const uint8_t* payloadData,
-                       const uint16_t payloadSize,
+                       const size_t payloadSize,
                        const WebRtcRTPHeader* rtpHeader));
 
   MOCK_METHOD2(OnRecoveredPacket,
-               bool(const uint8_t* packet, int packet_length));
+               bool(const uint8_t* packet, size_t packet_length));
 };
 
 class MockRtpRtcp : public RtpRtcp {
@@ -47,7 +47,7 @@
   MOCK_METHOD0(DeRegisterSyncModule,
       int32_t());
   MOCK_METHOD2(IncomingRtcpPacket,
-      int32_t(const uint8_t* incomingPacket, uint16_t packetLength));
+      int32_t(const uint8_t* incomingPacket, size_t packetLength));
   MOCK_METHOD1(SetRemoteSSRC, void(const uint32_t ssrc));
   MOCK_METHOD4(IncomingAudioNTP,
       int32_t(const uint32_t audioReceivedNTPsecs,
@@ -126,14 +126,14 @@
               const uint32_t timeStamp,
               int64_t capture_time_ms,
               const uint8_t* payloadData,
-              const uint32_t payloadSize,
+              const size_t payloadSize,
               const RTPFragmentationHeader* fragmentation,
               const RTPVideoHeader* rtpVideoHdr));
   MOCK_METHOD4(TimeToSendPacket,
       bool(uint32_t ssrc, uint16_t sequence_number, int64_t capture_time_ms,
            bool retransmission));
   MOCK_METHOD1(TimeToSendPadding,
-      int(int bytes));
+      size_t(size_t bytes));
   MOCK_CONST_METHOD2(GetSendSideDelay,
       bool(int* avg_send_delay_ms, int* max_send_delay_ms));
   MOCK_METHOD2(RegisterRtcpObservers,
@@ -172,7 +172,7 @@
   MOCK_METHOD0(ResetSendDataCountersRTP,
       int32_t());
   MOCK_CONST_METHOD2(DataCountersRTP,
-      int32_t(uint32_t *bytesSent, uint32_t *packetsSent));
+      int32_t(size_t *bytesSent, uint32_t *packetsSent));
   MOCK_METHOD1(RemoteRTCPStat,
       int32_t(RTCPSenderInfo* senderInfo));
   MOCK_CONST_METHOD1(RemoteRTCPStat,
diff --git a/webrtc/modules/rtp_rtcp/source/bitrate.cc b/webrtc/modules/rtp_rtcp/source/bitrate.cc
index 11b3cb2..0d50221 100644
--- a/webrtc/modules/rtp_rtcp/source/bitrate.cc
+++ b/webrtc/modules/rtp_rtcp/source/bitrate.cc
@@ -32,7 +32,7 @@
 
 Bitrate::~Bitrate() {}
 
-void Bitrate::Update(const int32_t bytes) {
+void Bitrate::Update(const size_t bytes) {
   CriticalSectionScoped cs(crit_.get());
   bytes_count_ += bytes;
   packet_count_++;
diff --git a/webrtc/modules/rtp_rtcp/source/bitrate.h b/webrtc/modules/rtp_rtcp/source/bitrate.h
index 36fa1d3..086db2a 100644
--- a/webrtc/modules/rtp_rtcp/source/bitrate.h
+++ b/webrtc/modules/rtp_rtcp/source/bitrate.h
@@ -35,7 +35,7 @@
   void Process();
 
   // Update with a packet.
-  void Update(const int32_t bytes);
+  void Update(const size_t bytes);
 
   // Packet rate last second, updated roughly every 100 ms.
   uint32_t PacketRate() const;
@@ -68,7 +68,7 @@
   int64_t bitrate_array_[10];
   int64_t bitrate_diff_ms_[10];
   int64_t time_last_rate_update_;
-  uint32_t bytes_count_;
+  size_t bytes_count_;
   uint32_t packet_count_;
   Observer* const observer_;
 };
diff --git a/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.cc b/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.cc
index e795841..0fcb6f7 100644
--- a/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.cc
+++ b/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.cc
@@ -71,10 +71,10 @@
 
 int32_t FecReceiverImpl::AddReceivedRedPacket(
     const RTPHeader& header, const uint8_t* incoming_rtp_packet,
-    int packet_length, uint8_t ulpfec_payload_type) {
+    size_t packet_length, uint8_t ulpfec_payload_type) {
   CriticalSectionScoped cs(crit_sect_.get());
   uint8_t REDHeaderLength = 1;
-  uint16_t payload_data_length = packet_length - header.headerLength;
+  size_t payload_data_length = packet_length - header.headerLength;
 
   // Add to list without RED header, aka a virtual RTP packet
   // we remove the RED header
diff --git a/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.h b/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.h
index b876bed..8dd02b3 100644
--- a/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.h
+++ b/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.h
@@ -30,7 +30,7 @@
 
   virtual int32_t AddReceivedRedPacket(const RTPHeader& rtp_header,
                                        const uint8_t* incoming_rtp_packet,
-                                       int packet_length,
+                                       size_t packet_length,
                                        uint8_t ulpfec_payload_type) OVERRIDE;
 
   virtual int32_t ProcessReceivedFec() OVERRIDE;
diff --git a/webrtc/modules/rtp_rtcp/source/fec_test_helper.cc b/webrtc/modules/rtp_rtcp/source/fec_test_helper.cc
index 0ffd5bf..a85e749 100644
--- a/webrtc/modules/rtp_rtcp/source/fec_test_helper.cc
+++ b/webrtc/modules/rtp_rtcp/source/fec_test_helper.cc
@@ -44,7 +44,7 @@
 
 // Creates a new RtpPacket with the RED header added to the packet.
 RtpPacket* FrameGenerator::BuildMediaRedPacket(const RtpPacket* packet) {
-  const int kHeaderLength = packet->header.header.headerLength;
+  const size_t kHeaderLength = packet->header.header.headerLength;
   RtpPacket* red_packet = new RtpPacket;
   red_packet->header = packet->header;
   red_packet->length = packet->length + 1;  // 1 byte RED header.
@@ -65,7 +65,7 @@
   ++num_packets_;
   RtpPacket* red_packet = NextPacket(0, packet->length + 1);
   red_packet->data[1] &= ~0x80;  // Clear marker bit.
-  const int kHeaderLength = red_packet->header.header.headerLength;
+  const size_t kHeaderLength = red_packet->header.header.headerLength;
   SetRedHeader(red_packet, kFecPayloadType, kHeaderLength);
   memcpy(red_packet->data + kHeaderLength + 1, packet->data, packet->length);
   red_packet->length = kHeaderLength + 1 + packet->length;
@@ -73,7 +73,7 @@
 }
 
 void FrameGenerator::SetRedHeader(Packet* red_packet, uint8_t payload_type,
-                                  int header_length) const {
+                                  size_t header_length) const {
   // Replace pltype.
   red_packet->data[1] &= 0x80;             // Reset.
   red_packet->data[1] += kRedPayloadType;  // Replace.
diff --git a/webrtc/modules/rtp_rtcp/source/fec_test_helper.h b/webrtc/modules/rtp_rtcp/source/fec_test_helper.h
index e6426ea..8253961 100644
--- a/webrtc/modules/rtp_rtcp/source/fec_test_helper.h
+++ b/webrtc/modules/rtp_rtcp/source/fec_test_helper.h
@@ -51,7 +51,7 @@
   RtpPacket* BuildFecRedPacket(const Packet* packet);
 
   void SetRedHeader(Packet* red_packet, uint8_t payload_type,
-                    int header_length) const;
+                    size_t header_length) const;
 
  private:
   static void BuildRtpHeader(uint8_t* data, const RTPHeader* header);
diff --git a/webrtc/modules/rtp_rtcp/source/forward_error_correction.cc b/webrtc/modules/rtp_rtcp/source/forward_error_correction.cc
index b02ea08..9010e7e 100644
--- a/webrtc/modules/rtp_rtcp/source/forward_error_correction.cc
+++ b/webrtc/modules/rtp_rtcp/source/forward_error_correction.cc
@@ -693,7 +693,7 @@
 
   // XOR with RTP payload.
   // TODO(marpan/ajm): Are we doing more XORs than required here?
-  for (int32_t i = kRtpHeaderSize; i < src_packet->length; ++i) {
+  for (size_t i = kRtpHeaderSize; i < src_packet->length; ++i) {
     dst_packet->pkt->data[i] ^= src_packet->data[i];
   }
 }
@@ -816,7 +816,7 @@
   return 0;
 }
 
-uint16_t ForwardErrorCorrection::PacketOverhead() {
+size_t ForwardErrorCorrection::PacketOverhead() {
   return kFecHeaderSize + kUlpHeaderSizeLBitSet;
 }
 }  // namespace webrtc
diff --git a/webrtc/modules/rtp_rtcp/source/forward_error_correction.h b/webrtc/modules/rtp_rtcp/source/forward_error_correction.h
index bb790f3..a3b3fa0 100644
--- a/webrtc/modules/rtp_rtcp/source/forward_error_correction.h
+++ b/webrtc/modules/rtp_rtcp/source/forward_error_correction.h
@@ -49,7 +49,7 @@
     // reaches zero.
     virtual int32_t Release();
 
-    uint16_t length;               // Length of packet in bytes.
+    size_t length;               // Length of packet in bytes.
     uint8_t data[IP_PACKET_SIZE];  // Packet data.
 
    private:
@@ -200,7 +200,7 @@
   // Gets the size in bytes of the FEC/ULP headers, which must be accounted for
   // as packet overhead.
   // \return Packet overhead in bytes.
-  static uint16_t PacketOverhead();
+  static size_t PacketOverhead();
 
   // Reset internal states from last frame and clear the recovered_packet_list.
   // Frees all memory allocated by this class.
diff --git a/webrtc/modules/rtp_rtcp/source/nack_rtx_unittest.cc b/webrtc/modules/rtp_rtcp/source/nack_rtx_unittest.cc
index b852205..d6e557d 100644
--- a/webrtc/modules/rtp_rtcp/source/nack_rtx_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/nack_rtx_unittest.cc
@@ -40,7 +40,7 @@
 
   virtual int32_t OnReceivedPayloadData(
       const uint8_t* data,
-      const uint16_t size,
+      const size_t size,
       const webrtc::WebRtcRTPHeader* rtp_header) OVERRIDE {
     if (!sequence_numbers_.empty())
       EXPECT_EQ(kTestSsrc, rtp_header->header.ssrc);
@@ -95,7 +95,7 @@
     packet_loss_ = 0;
   }
 
-  virtual int SendPacket(int channel, const void *data, int len) OVERRIDE {
+  virtual int SendPacket(int channel, const void *data, size_t len) OVERRIDE {
     count_++;
     const unsigned char* ptr = static_cast<const unsigned  char*>(data);
     uint32_t ssrc = (ptr[8] << 24) + (ptr[9] << 16) + (ptr[10] << 8) + ptr[11];
@@ -105,13 +105,13 @@
         sequence_number);
     if (packet_loss_ > 0) {
       if ((count_ % packet_loss_) == 0) {
-        return len;
+        return static_cast<int>(len);
       }
     } else if (count_ >= consecutive_drop_start_ &&
         count_ < consecutive_drop_end_) {
-      return len;
+      return static_cast<int>(len);
     }
-    int packet_length = len;
+    size_t packet_length = len;
     // TODO(pbos): Figure out why this needs to be initialized. Likely this
     // is hiding a bug either in test setup or other code.
     // https://code.google.com/p/webrtc/issues/detail?id=3183
@@ -143,12 +143,14 @@
                                           true)) {
       return -1;
     }
-    return len;
+    return static_cast<int>(len);
   }
 
-  virtual int SendRTCPPacket(int channel, const void *data, int len) OVERRIDE {
+  virtual int SendRTCPPacket(int channel,
+                             const void *data,
+                             size_t len) OVERRIDE {
     if (module_->IncomingRtcpPacket((const uint8_t*)data, len) == 0) {
-      return len;
+      return static_cast<int>(len);
     }
     return -1;
   }
@@ -214,7 +216,7 @@
                                                        0,
                                                        video_codec.maxBitrate));
 
-    for (int n = 0; n < payload_data_length; n++) {
+    for (size_t n = 0; n < payload_data_length; n++) {
       payload_data[n] = n % 10;
     }
   }
@@ -292,7 +294,7 @@
   RtxLoopBackTransport transport_;
   VerifyingRtxReceiver receiver_;
   uint8_t  payload_data[65000];
-  int payload_data_length;
+  size_t payload_data_length;
   SimulatedClock fake_clock;
 };
 
diff --git a/webrtc/modules/rtp_rtcp/source/producer_fec.cc b/webrtc/modules/rtp_rtcp/source/producer_fec.cc
index 747cd89..a571a01 100644
--- a/webrtc/modules/rtp_rtcp/source/producer_fec.cc
+++ b/webrtc/modules/rtp_rtcp/source/producer_fec.cc
@@ -36,7 +36,7 @@
   ForwardErrorCorrection::Packet* pkt;
 };
 
-RedPacket::RedPacket(int length)
+RedPacket::RedPacket(size_t length)
     : data_(new uint8_t[length]),
       length_(length),
       header_length_(0) {
@@ -46,7 +46,7 @@
   delete [] data_;
 }
 
-void RedPacket::CreateHeader(const uint8_t* rtp_header, int header_length,
+void RedPacket::CreateHeader(const uint8_t* rtp_header, size_t header_length,
                              int red_pl_type, int pl_type) {
   assert(header_length + kREDForFECHeaderLength <= length_);
   memcpy(data_, rtp_header, header_length);
@@ -64,7 +64,7 @@
   RtpUtility::AssignUWord16ToBuffer(&data_[2], seq_num);
 }
 
-void RedPacket::AssignPayload(const uint8_t* payload, int length) {
+void RedPacket::AssignPayload(const uint8_t* payload, size_t length) {
   assert(header_length_ + length <= length_);
   memcpy(data_ + header_length_, payload, length);
 }
@@ -77,7 +77,7 @@
   return data_;
 }
 
-int RedPacket::length() const {
+size_t RedPacket::length() const {
   return length_;
 }
 
@@ -120,8 +120,8 @@
 }
 
 RedPacket* ProducerFec::BuildRedPacket(const uint8_t* data_buffer,
-                                       int payload_length,
-                                       int rtp_header_length,
+                                       size_t payload_length,
+                                       size_t rtp_header_length,
                                        int red_pl_type) {
   RedPacket* red_packet = new RedPacket(payload_length +
                                         kREDForFECHeaderLength +
@@ -134,8 +134,8 @@
 }
 
 int ProducerFec::AddRtpPacketAndGenerateFec(const uint8_t* data_buffer,
-                                            int payload_length,
-                                            int rtp_header_length) {
+                                            size_t payload_length,
+                                            size_t rtp_header_length) {
   assert(fec_packets_.empty());
   if (media_packets_fec_.empty()) {
     params_ = new_params_;
@@ -210,7 +210,7 @@
 RedPacket* ProducerFec::GetFecPacket(int red_pl_type,
                                      int fec_pl_type,
                                      uint16_t seq_num,
-                                     int rtp_header_length) {
+                                     size_t rtp_header_length) {
   if (fec_packets_.empty())
     return NULL;
   // Build FEC packet. The FEC packets in |fec_packets_| doesn't
diff --git a/webrtc/modules/rtp_rtcp/source/producer_fec.h b/webrtc/modules/rtp_rtcp/source/producer_fec.h
index e3f9d1d..ec58bcf 100644
--- a/webrtc/modules/rtp_rtcp/source/producer_fec.h
+++ b/webrtc/modules/rtp_rtcp/source/producer_fec.h
@@ -21,20 +21,20 @@
 
 class RedPacket {
  public:
-  explicit RedPacket(int length);
+  explicit RedPacket(size_t length);
   ~RedPacket();
-  void CreateHeader(const uint8_t* rtp_header, int header_length,
+  void CreateHeader(const uint8_t* rtp_header, size_t header_length,
                     int red_pl_type, int pl_type);
   void SetSeqNum(int seq_num);
-  void AssignPayload(const uint8_t* payload, int length);
+  void AssignPayload(const uint8_t* payload, size_t length);
   void ClearMarkerBit();
   uint8_t* data() const;
-  int length() const;
+  size_t length() const;
 
  private:
   uint8_t* data_;
-  int length_;
-  int header_length_;
+  size_t length_;
+  size_t header_length_;
 };
 
 class ProducerFec {
@@ -46,13 +46,13 @@
                         int max_fec_frames);
 
   RedPacket* BuildRedPacket(const uint8_t* data_buffer,
-                            int payload_length,
-                            int rtp_header_length,
+                            size_t payload_length,
+                            size_t rtp_header_length,
                             int red_pl_type);
 
   int AddRtpPacketAndGenerateFec(const uint8_t* data_buffer,
-                                 int payload_length,
-                                 int rtp_header_length);
+                                 size_t payload_length,
+                                 size_t rtp_header_length);
 
   bool ExcessOverheadBelowMax();
 
@@ -63,7 +63,7 @@
   RedPacket* GetFecPacket(int red_pl_type,
                           int fec_pl_type,
                           uint16_t seq_num,
-                          int rtp_header_length);
+                          size_t rtp_header_length);
 
  private:
   void DeletePackets();
diff --git a/webrtc/modules/rtp_rtcp/source/producer_fec_unittest.cc b/webrtc/modules/rtp_rtcp/source/producer_fec_unittest.cc
index baa3827..d8b67a7 100644
--- a/webrtc/modules/rtp_rtcp/source/producer_fec_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/producer_fec_unittest.cc
@@ -23,7 +23,7 @@
                   int fec_pltype,
                   RedPacket* packet,
                   bool marker_bit) {
-  EXPECT_GT(packet->length(), static_cast<int>(kRtpHeaderSize));
+  EXPECT_GT(packet->length(), kRtpHeaderSize);
   EXPECT_TRUE(packet->data() != NULL);
   uint8_t* data = packet->data();
   // Marker bit not set.
diff --git a/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.cc b/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.cc
index f063ce3..eeb6e31 100644
--- a/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.cc
+++ b/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.cc
@@ -123,7 +123,7 @@
     last_receive_time_ms_ = clock_->TimeInMilliseconds();
   }
 
-  uint16_t packet_oh = header.headerLength + header.paddingLength;
+  size_t packet_oh = header.headerLength + header.paddingLength;
 
   // Our measured overhead. Filter from RFC 5104 4.2.1.2:
   // avg_OH (new) = 15/16*avg_OH (old) + 1/16*pckt_OH,
@@ -303,7 +303,7 @@
 }
 
 void StreamStatisticianImpl::GetDataCounters(
-    uint32_t* bytes_received, uint32_t* packets_received) const {
+    size_t* bytes_received, uint32_t* packets_received) const {
   CriticalSectionScoped cs(stream_lock_.get());
   if (bytes_received) {
     *bytes_received = receive_counters_.bytes + receive_counters_.header_bytes +
diff --git a/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.h b/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.h
index 40ca285..bef856f 100644
--- a/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.h
+++ b/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.h
@@ -31,7 +31,7 @@
   virtual ~StreamStatisticianImpl() {}
 
   virtual bool GetStatistics(RtcpStatistics* statistics, bool reset) OVERRIDE;
-  virtual void GetDataCounters(uint32_t* bytes_received,
+  virtual void GetDataCounters(size_t* bytes_received,
                                uint32_t* packets_received) const OVERRIDE;
   virtual uint32_t BitrateReceived() const OVERRIDE;
   virtual void ResetStatistics() OVERRIDE;
@@ -80,7 +80,7 @@
   uint16_t received_seq_wraps_;
 
   // Current counter values.
-  uint16_t received_packet_overhead_;
+  size_t received_packet_overhead_;
   StreamDataCounters receive_counters_;
 
   // Counter values when we sent the last report.
diff --git a/webrtc/modules/rtp_rtcp/source/receive_statistics_unittest.cc b/webrtc/modules/rtp_rtcp/source/receive_statistics_unittest.cc
index 5b4d0dd..808a880 100644
--- a/webrtc/modules/rtp_rtcp/source/receive_statistics_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/receive_statistics_unittest.cc
@@ -16,8 +16,8 @@
 
 namespace webrtc {
 
-const int kPacketSize1 = 100;
-const int kPacketSize2 = 300;
+const size_t kPacketSize1 = 100;
+const size_t kPacketSize2 = 300;
 const uint32_t kSsrc1 = 1;
 const uint32_t kSsrc2 = 2;
 
@@ -56,7 +56,7 @@
       receive_statistics_->GetStatistician(kSsrc1);
   ASSERT_TRUE(statistician != NULL);
   EXPECT_GT(statistician->BitrateReceived(), 0u);
-  uint32_t bytes_received = 0;
+  size_t bytes_received = 0;
   uint32_t packets_received = 0;
   statistician->GetDataCounters(&bytes_received, &packets_received);
   EXPECT_EQ(200u, bytes_received);
@@ -125,7 +125,7 @@
   StreamStatistician* statistician =
       receive_statistics_->GetStatistician(kSsrc1);
   ASSERT_TRUE(statistician != NULL);
-  uint32_t bytes_received = 0;
+  size_t bytes_received = 0;
   uint32_t packets_received = 0;
   statistician->GetDataCounters(&bytes_received, &packets_received);
   EXPECT_EQ(200u, bytes_received);
@@ -234,8 +234,8 @@
 
   void ExpectMatches(uint32_t num_calls,
                      uint32_t ssrc,
-                     uint32_t bytes,
-                     uint32_t padding,
+                     size_t bytes,
+                     size_t padding,
                      uint32_t packets,
                      uint32_t retransmits,
                      uint32_t fec) {
@@ -257,8 +257,8 @@
   RtpTestCallback callback;
   receive_statistics_->RegisterRtpStatisticsCallback(&callback);
 
-  const uint32_t kHeaderLength = 20;
-  const uint32_t kPaddingLength = 9;
+  const size_t kHeaderLength = 20;
+  const size_t kPaddingLength = 9;
 
   // One packet of size kPacketSize1.
   header1_.headerLength = kHeaderLength;
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_format_remb_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_format_remb_unittest.cc
index 17671b7..6a7b7f9 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_format_remb_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_format_remb_unittest.cc
@@ -32,14 +32,14 @@
 
   virtual int SendPacket(int /*channel*/,
                          const void* /*data*/,
-                         int /*len*/) OVERRIDE {
+                         size_t /*len*/) OVERRIDE {
     return -1;
   }
   virtual int SendRTCPPacket(int /*channel*/,
                              const void *packet,
-                             int packetLength) OVERRIDE {
+                             size_t packetLength) OVERRIDE {
     RTCPUtility::RTCPParserV2 rtcpParser((uint8_t*)packet,
-                                         (int32_t)packetLength,
+                                         packetLength,
                                          true); // Allow non-compound RTCP
 
     EXPECT_TRUE(rtcpParser.IsValid());
@@ -51,7 +51,7 @@
               rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRemb);
     EXPECT_EQ((uint32_t)1234,
               rtcpPacketInformation.receiverEstimatedMaxBitrate);
-    return packetLength;
+    return static_cast<int>(packetLength);
   }
  private:
   RTCPReceiver* rtcp_receiver_;
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc
index 2a61573..d65157d 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc
@@ -41,7 +41,7 @@
   }
   virtual int SendPacket(int /*ch*/,
                          const void* /*data*/,
-                         int /*len*/) OVERRIDE {
+                         size_t /*len*/) OVERRIDE {
     ADD_FAILURE();  // FAIL() gives a compile error.
     return -1;
   }
@@ -49,13 +49,13 @@
   // Injects an RTCP packet into the receiver.
   virtual int SendRTCPPacket(int /* ch */,
                              const void *packet,
-                             int packet_len) OVERRIDE {
+                             size_t packet_len) OVERRIDE {
     ADD_FAILURE();
     return 0;
   }
 
   virtual int OnReceivedPayloadData(const uint8_t* payloadData,
-                                    const uint16_t payloadSize,
+                                    const size_t payloadSize,
                                     const WebRtcRTPHeader* rtpHeader) OVERRIDE {
     ADD_FAILURE();
     return 0;
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc
index 1752ab9..9991992 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc
@@ -1633,7 +1633,7 @@
   {
       return -1;
   }
-  return SendToNetwork(rtcp_buffer, static_cast<uint16_t>(rtcp_length));
+  return SendToNetwork(rtcp_buffer, static_cast<size_t>(rtcp_length));
 }
 
 int RTCPSender::PrepareRTCP(const FeedbackState& feedback_state,
@@ -2000,7 +2000,7 @@
 
 int32_t
 RTCPSender::SendToNetwork(const uint8_t* dataBuffer,
-                          const uint16_t length)
+                          const size_t length)
 {
     CriticalSectionScoped lock(_criticalSectionTransport);
     if(_cbTransport)
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender.h b/webrtc/modules/rtp_rtcp/source/rtcp_sender.h
index 668c7c7..23f720fc 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_sender.h
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender.h
@@ -56,7 +56,7 @@
    uint8_t send_payload_type;
    uint32_t frequency_hz;
    uint32_t packets_sent;
-   uint32_t media_bytes_sent;
+   size_t media_bytes_sent;
    uint32_t send_bitrate;
 
    uint32_t last_rr_ntp_secs;
@@ -177,7 +177,7 @@
     void GetPacketTypeCounter(RtcpPacketTypeCounter* packet_counter) const;
 
 private:
-    int32_t SendToNetwork(const uint8_t* dataBuffer, const uint16_t length);
+    int32_t SendToNetwork(const uint8_t* dataBuffer, const size_t length);
 
     int32_t WriteAllReportBlocksToBuffer(uint8_t* rtcpbuffer,
                             int pos,
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc
index 44d4a2b..a72fe58 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc
@@ -188,7 +188,7 @@
 void CreateRtpPacket(const bool marker_bit, const uint8_t payload,
     const uint16_t seq_num, const uint32_t timestamp,
     const uint32_t ssrc, uint8_t* array,
-    uint16_t* cur_pos) {
+    size_t* cur_pos) {
   ASSERT_TRUE(payload <= 127);
   array[(*cur_pos)++] = 0x80;
   array[(*cur_pos)++] = payload | (marker_bit ? 0x80 : 0);
@@ -229,15 +229,15 @@
   }
   virtual int SendPacket(int /*ch*/,
                          const void* /*data*/,
-                         int /*len*/) OVERRIDE {
+                         size_t /*len*/) OVERRIDE {
     return -1;
   }
 
   virtual int SendRTCPPacket(int /*ch*/,
                              const void *packet,
-                             int packet_len) OVERRIDE {
+                             size_t packet_len) OVERRIDE {
     RTCPUtility::RTCPParserV2 rtcpParser((uint8_t*)packet,
-                                         (int32_t)packet_len,
+                                         packet_len,
                                          true); // Allow non-compound RTCP
 
     EXPECT_TRUE(rtcpParser.IsValid());
@@ -262,11 +262,11 @@
     rtcp_packet_info_.ntp_frac = rtcpPacketInformation.ntp_frac;
     rtcp_packet_info_.rtp_timestamp = rtcpPacketInformation.rtp_timestamp;
 
-    return packet_len;
+    return static_cast<int>(packet_len);
   }
 
   virtual int OnReceivedPayloadData(const uint8_t* payloadData,
-                                    const uint16_t payloadSize,
+                                    const size_t payloadSize,
                                     const WebRtcRTPHeader* rtpHeader) OVERRIDE {
     return 0;
   }
@@ -357,10 +357,10 @@
   const uint16_t seq_num = 11111;
   const uint32_t timestamp = 1234567;
   const uint32_t ssrc = 0x11111111;
-  uint16_t packet_length = 0;
+  size_t packet_length = 0;
   CreateRtpPacket(marker_bit, payload, seq_num, timestamp, ssrc, packet_,
       &packet_length);
-  EXPECT_EQ(25, packet_length);
+  EXPECT_EQ(25u, packet_length);
 
   VideoCodec codec_inst;
   strncpy(codec_inst.plName, "VP8", webrtc::kPayloadNameSize - 1);
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_fec_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_fec_unittest.cc
index 9d19fde..5a3eb39 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_fec_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_fec_unittest.cc
@@ -896,7 +896,7 @@
   for (int i = 0; i < num_media_packets; ++i) {
     media_packet = new ForwardErrorCorrection::Packet;
     media_packet_list_.push_back(media_packet);
-    media_packet->length = static_cast<uint16_t>(
+    media_packet->length = static_cast<size_t>(
         (static_cast<float>(rand()) / RAND_MAX) *
         (IP_PACKET_SIZE - kRtpHeaderSize - kTransportOverhead -
          ForwardErrorCorrection::PacketOverhead()));
@@ -928,7 +928,7 @@
     webrtc::RtpUtility::AssignUWord32ToBuffer(&media_packet->data[8], ssrc_);
 
     // Generate random values for payload.
-    for (int j = 12; j < media_packet->length; ++j) {
+    for (size_t j = 12; j < media_packet->length; ++j) {
       media_packet->data[j] = static_cast<uint8_t>(rand() % 256);
     }
     sequence_number++;
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.cc b/webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.cc
index ab210ec..1fa288a 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.cc
@@ -36,7 +36,7 @@
   payload_size_ = payload_size;
 
   // Fragment packets more evenly by splitting the payload up evenly.
-  uint32_t num_packets =
+  size_t num_packets =
       (payload_size_ + max_payload_len_ - 1) / max_payload_len_;
   payload_length_ = (payload_size_ + num_packets - 1) / num_packets;
   assert(payload_length_ <= max_payload_len_);
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h b/webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h
index 491cab5..2fd6aad 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h
@@ -57,7 +57,7 @@
   size_t payload_size_;
   const size_t max_payload_len_;
   FrameType frame_type_;
-  uint32_t payload_length_;
+  size_t payload_length_;
   uint8_t generic_header_;
 
   DISALLOW_COPY_AND_ASSIGN(RtpPacketizerGeneric);
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_format_vp8.cc b/webrtc/modules/rtp_rtcp/source/rtp_format_vp8.cc
index d74e04f..57ff74f 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_format_vp8.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_format_vp8.cc
@@ -22,17 +22,17 @@
 namespace {
 int ParseVP8PictureID(RTPVideoHeaderVP8* vp8,
                       const uint8_t** data,
-                      int* data_length,
-                      int* parsed_bytes) {
+                      size_t* data_length,
+                      size_t* parsed_bytes) {
   assert(vp8 != NULL);
-  if (*data_length <= 0)
+  if (*data_length == 0)
     return -1;
 
   vp8->pictureId = (**data & 0x7F);
   if (**data & 0x80) {
     (*data)++;
     (*parsed_bytes)++;
-    if (--(*data_length) <= 0)
+    if (--(*data_length) == 0)
       return -1;
     // PictureId is 15 bits
     vp8->pictureId = (vp8->pictureId << 8) + **data;
@@ -45,10 +45,10 @@
 
 int ParseVP8Tl0PicIdx(RTPVideoHeaderVP8* vp8,
                       const uint8_t** data,
-                      int* data_length,
-                      int* parsed_bytes) {
+                      size_t* data_length,
+                      size_t* parsed_bytes) {
   assert(vp8 != NULL);
-  if (*data_length <= 0)
+  if (*data_length == 0)
     return -1;
 
   vp8->tl0PicIdx = **data;
@@ -60,12 +60,12 @@
 
 int ParseVP8TIDAndKeyIdx(RTPVideoHeaderVP8* vp8,
                          const uint8_t** data,
-                         int* data_length,
-                         int* parsed_bytes,
+                         size_t* data_length,
+                         size_t* parsed_bytes,
                          bool has_tid,
                          bool has_key_idx) {
   assert(vp8 != NULL);
-  if (*data_length <= 0)
+  if (*data_length == 0)
     return -1;
 
   if (has_tid) {
@@ -83,11 +83,10 @@
 
 int ParseVP8Extension(RTPVideoHeaderVP8* vp8,
                       const uint8_t* data,
-                      int data_length) {
+                      size_t data_length) {
   assert(vp8 != NULL);
-  int parsed_bytes = 0;
-  if (data_length <= 0)
-    return -1;
+  assert(data_length > 0);
+  size_t parsed_bytes = 0;
   // Optional X field is present.
   bool has_picture_id = (*data & 0x80) ? true : false;   // I bit
   bool has_tl0_pic_idx = (*data & 0x40) ? true : false;  // L bit
@@ -118,12 +117,12 @@
       return -1;
     }
   }
-  return parsed_bytes;
+  return static_cast<int>(parsed_bytes);
 }
 
 int ParseVP8FrameSize(RtpDepacketizer::ParsedPayload* parsed_payload,
                       const uint8_t* data,
-                      int data_length) {
+                      size_t data_length) {
   assert(parsed_payload != NULL);
   if (parsed_payload->frame_type != kVideoFrameKey) {
     // Included in payload header for I-frames.
@@ -149,7 +148,7 @@
                                                                  false};
 
 RtpPacketizerVp8::RtpPacketizerVp8(const RTPVideoHeaderVP8& hdr_info,
-                                   int max_payload_len,
+                                   size_t max_payload_len,
                                    VP8PacketizerMode mode)
     : payload_data_(NULL),
       payload_size_(0),
@@ -164,7 +163,7 @@
 }
 
 RtpPacketizerVp8::RtpPacketizerVp8(const RTPVideoHeaderVP8& hdr_info,
-                                   int max_payload_len)
+                                   size_t max_payload_len)
     : payload_data_(NULL),
       payload_size_(0),
       part_info_(),
@@ -222,7 +221,7 @@
   if (bytes < 0) {
     return false;
   }
-  *bytes_to_send = bytes;
+  *bytes_to_send = static_cast<size_t>(bytes);
 
   *last_packet = packets_.empty();
   return true;
@@ -251,9 +250,9 @@
   return "RtpPacketizerVp8";
 }
 
-int RtpPacketizerVp8::CalcNextSize(int max_payload_len,
-                                   int remaining_bytes,
-                                   bool split_payload) const {
+size_t RtpPacketizerVp8::CalcNextSize(size_t max_payload_len,
+                                      size_t remaining_bytes,
+                                      bool split_payload) const {
   if (max_payload_len == 0 || remaining_bytes == 0) {
     return 0;
   }
@@ -265,10 +264,10 @@
     // Balance payload sizes to produce (almost) equal size
     // fragments.
     // Number of fragments for remaining_bytes:
-    int num_frags = remaining_bytes / max_payload_len + 1;
+    size_t num_frags = remaining_bytes / max_payload_len + 1;
     // Number of bytes in this fragment:
-    return static_cast<int>(static_cast<double>(remaining_bytes) / num_frags +
-                            0.5);
+    return static_cast<size_t>(
+        static_cast<double>(remaining_bytes) / num_frags + 0.5);
   } else {
     return max_payload_len >= remaining_bytes ? remaining_bytes
                                               : max_payload_len;
@@ -282,22 +281,22 @@
     // descriptor and one payload byte. Return an error.
     return -1;
   }
-  int total_bytes_processed = 0;
+  size_t total_bytes_processed = 0;
   bool start_on_new_fragment = true;
   bool beginning = true;
-  int part_ix = 0;
+  size_t part_ix = 0;
   while (total_bytes_processed < payload_size_) {
-    int packet_bytes = 0;       // How much data to send in this packet.
+    size_t packet_bytes = 0;    // How much data to send in this packet.
     bool split_payload = true;  // Splitting of partitions is initially allowed.
-    int remaining_in_partition = part_info_.fragmentationOffset[part_ix] -
+    size_t remaining_in_partition = part_info_.fragmentationOffset[part_ix] -
                                  total_bytes_processed +
                                  part_info_.fragmentationLength[part_ix];
-    int rem_payload_len =
+    size_t rem_payload_len =
         max_payload_len_ -
         (vp8_fixed_payload_descriptor_bytes_ + PayloadDescriptorExtraLength());
-    int first_partition_in_packet = part_ix;
+    size_t first_partition_in_packet = part_ix;
 
-    while (int next_size = CalcNextSize(
+    while (size_t next_size = CalcNextSize(
                rem_payload_len, remaining_in_partition, split_payload)) {
       packet_bytes += next_size;
       rem_payload_len -= next_size;
@@ -348,44 +347,44 @@
     return -1;
   }
   std::vector<int> partition_decision;
-  const int overhead =
+  const size_t overhead =
       vp8_fixed_payload_descriptor_bytes_ + PayloadDescriptorExtraLength();
-  const uint32_t max_payload_len = max_payload_len_ - overhead;
+  const size_t max_payload_len = max_payload_len_ - overhead;
   int min_size, max_size;
   AggregateSmallPartitions(&partition_decision, &min_size, &max_size);
 
-  int total_bytes_processed = 0;
-  int part_ix = 0;
+  size_t total_bytes_processed = 0;
+  size_t part_ix = 0;
   while (part_ix < num_partitions_) {
     if (partition_decision[part_ix] == -1) {
       // Split large partitions.
-      int remaining_partition = part_info_.fragmentationLength[part_ix];
-      int num_fragments = Vp8PartitionAggregator::CalcNumberOfFragments(
+      size_t remaining_partition = part_info_.fragmentationLength[part_ix];
+      size_t num_fragments = Vp8PartitionAggregator::CalcNumberOfFragments(
           remaining_partition, max_payload_len, overhead, min_size, max_size);
-      const int packet_bytes =
+      const size_t packet_bytes =
           (remaining_partition + num_fragments - 1) / num_fragments;
-      for (int n = 0; n < num_fragments; ++n) {
-        const int this_packet_bytes = packet_bytes < remaining_partition
-                                          ? packet_bytes
-                                          : remaining_partition;
+      for (size_t n = 0; n < num_fragments; ++n) {
+        const size_t this_packet_bytes = packet_bytes < remaining_partition
+                                             ? packet_bytes
+                                             : remaining_partition;
         QueuePacket(
             total_bytes_processed, this_packet_bytes, part_ix, (n == 0));
         remaining_partition -= this_packet_bytes;
         total_bytes_processed += this_packet_bytes;
-        if (this_packet_bytes < min_size) {
+        if (static_cast<int>(this_packet_bytes) < min_size) {
           min_size = this_packet_bytes;
         }
-        if (this_packet_bytes > max_size) {
+        if (static_cast<int>(this_packet_bytes) > max_size) {
           max_size = this_packet_bytes;
         }
       }
       assert(remaining_partition == 0);
       ++part_ix;
     } else {
-      int this_packet_bytes = 0;
-      const int first_partition_in_packet = part_ix;
+      size_t this_packet_bytes = 0;
+      const size_t first_partition_in_packet = part_ix;
       const int aggregation_index = partition_decision[part_ix];
-      while (static_cast<size_t>(part_ix) < partition_decision.size() &&
+      while (part_ix < partition_decision.size() &&
              partition_decision[part_ix] == aggregation_index) {
         // Collect all partitions that were aggregated into the same packet.
         this_packet_bytes += part_info_.fragmentationLength[part_ix];
@@ -410,11 +409,11 @@
   *max_size = -1;
   assert(partition_vec);
   partition_vec->assign(num_partitions_, -1);
-  const int overhead =
+  const size_t overhead =
       vp8_fixed_payload_descriptor_bytes_ + PayloadDescriptorExtraLength();
-  const uint32_t max_payload_len = max_payload_len_ - overhead;
-  int first_in_set = 0;
-  int last_in_set = 0;
+  const size_t max_payload_len = max_payload_len_ - overhead;
+  size_t first_in_set = 0;
+  size_t last_in_set = 0;
   int num_aggregate_packets = 0;
   // Find sets of partitions smaller than max_payload_len_.
   while (first_in_set < num_partitions_) {
@@ -434,7 +433,7 @@
       Vp8PartitionAggregator::ConfigVec optimal_config =
           aggregator.FindOptimalConfiguration(max_payload_len, overhead);
       aggregator.CalcMinMax(optimal_config, min_size, max_size);
-      for (int i = first_in_set, j = 0; i <= last_in_set; ++i, ++j) {
+      for (size_t i = first_in_set, j = 0; i <= last_in_set; ++i, ++j) {
         // Transfer configuration for this set of partitions to the joint
         // partition vector representing all partitions in the frame.
         (*partition_vec)[i] = num_aggregate_packets + optimal_config[j];
@@ -446,9 +445,9 @@
   }
 }
 
-void RtpPacketizerVp8::QueuePacket(int start_pos,
-                                   int packet_size,
-                                   int first_partition_in_packet,
+void RtpPacketizerVp8::QueuePacket(size_t start_pos,
+                                   size_t packet_size,
+                                   size_t first_partition_in_packet,
                                    bool start_on_new_fragment) {
   // Write info to packet info struct and store in packet info queue.
   InfoStruct packet_info;
@@ -461,7 +460,7 @@
 
 int RtpPacketizerVp8::WriteHeaderAndPayload(const InfoStruct& packet_info,
                                             uint8_t* buffer,
-                                            int buffer_length) const {
+                                            size_t buffer_length) const {
   // Write the VP8 payload descriptor.
   //       0
   //       0 1 2 3 4 5 6 7 8
@@ -488,6 +487,8 @@
   buffer[0] |= (packet_info.first_partition_ix & kPartIdField);
 
   const int extension_length = WriteExtensionFields(buffer, buffer_length);
+  if (extension_length < 0)
+    return -1;
 
   memcpy(&buffer[vp8_fixed_payload_descriptor_bytes_ + extension_length],
          &payload_data_[packet_info.payload_start_pos],
@@ -499,8 +500,8 @@
 }
 
 int RtpPacketizerVp8::WriteExtensionFields(uint8_t* buffer,
-                                           int buffer_length) const {
-  int extension_length = 0;
+                                           size_t buffer_length) const {
+  size_t extension_length = 0;
   if (XFieldPresent()) {
     uint8_t* x_field = buffer + vp8_fixed_payload_descriptor_bytes_;
     *x_field = 0;
@@ -525,14 +526,16 @@
     }
     assert(extension_length == PayloadDescriptorExtraLength());
   }
-  return extension_length;
+  return static_cast<int>(extension_length);
 }
 
 int RtpPacketizerVp8::WritePictureIDFields(uint8_t* x_field,
                                            uint8_t* buffer,
-                                           int buffer_length,
-                                           int* extension_length) const {
+                                           size_t buffer_length,
+                                           size_t* extension_length) const {
   *x_field |= kIBit;
+  assert(buffer_length >=
+      vp8_fixed_payload_descriptor_bytes_ + *extension_length);
   const int pic_id_length = WritePictureID(
       buffer + vp8_fixed_payload_descriptor_bytes_ + *extension_length,
       buffer_length - vp8_fixed_payload_descriptor_bytes_ - *extension_length);
@@ -542,9 +545,10 @@
   return 0;
 }
 
-int RtpPacketizerVp8::WritePictureID(uint8_t* buffer, int buffer_length) const {
+int RtpPacketizerVp8::WritePictureID(uint8_t* buffer,
+                                     size_t buffer_length) const {
   const uint16_t pic_id = static_cast<uint16_t>(hdr_info_.pictureId);
-  int picture_id_len = PictureIdLength();
+  size_t picture_id_len = PictureIdLength();
   if (picture_id_len > buffer_length)
     return -1;
   if (picture_id_len == 2) {
@@ -553,13 +557,13 @@
   } else if (picture_id_len == 1) {
     buffer[0] = pic_id & 0x7F;
   }
-  return picture_id_len;
+  return static_cast<int>(picture_id_len);
 }
 
 int RtpPacketizerVp8::WriteTl0PicIdxFields(uint8_t* x_field,
                                            uint8_t* buffer,
-                                           int buffer_length,
-                                           int* extension_length) const {
+                                           size_t buffer_length,
+                                           size_t* extension_length) const {
   if (buffer_length <
       vp8_fixed_payload_descriptor_bytes_ + *extension_length + 1) {
     return -1;
@@ -573,8 +577,8 @@
 
 int RtpPacketizerVp8::WriteTIDAndKeyIdxFields(uint8_t* x_field,
                                               uint8_t* buffer,
-                                              int buffer_length,
-                                              int* extension_length) const {
+                                              size_t buffer_length,
+                                              size_t* extension_length) const {
   if (buffer_length <
       vp8_fixed_payload_descriptor_bytes_ + *extension_length + 1) {
     return -1;
@@ -596,8 +600,8 @@
   return 0;
 }
 
-int RtpPacketizerVp8::PayloadDescriptorExtraLength() const {
-  int length_bytes = PictureIdLength();
+size_t RtpPacketizerVp8::PayloadDescriptorExtraLength() const {
+  size_t length_bytes = PictureIdLength();
   if (TL0PicIdxFieldPresent())
     ++length_bytes;
   if (TIDFieldPresent() || KeyIdxFieldPresent())
@@ -607,7 +611,7 @@
   return length_bytes;
 }
 
-int RtpPacketizerVp8::PictureIdLength() const {
+size_t RtpPacketizerVp8::PictureIdLength() const {
   if (hdr_info_.pictureId == kNoPictureId) {
     return 0;
   }
@@ -693,6 +697,10 @@
 
   // Advance payload_data and decrease remaining payload size.
   payload_data++;
+  if (payload_data_length <= 1) {
+    LOG(LS_ERROR) << "Error parsing VP8 payload descriptor!";
+    return false;
+  }
   payload_data_length--;
 
   if (extension) {
@@ -704,15 +712,14 @@
       return false;
     payload_data += parsed_bytes;
     payload_data_length -= parsed_bytes;
-  }
-
-  if (payload_data_length <= 0) {
-    LOG(LS_ERROR) << "Error parsing VP8 payload descriptor!";
-    return false;
+    if (payload_data_length == 0) {
+      LOG(LS_ERROR) << "Error parsing VP8 payload descriptor!";
+      return false;
+    }
   }
 
   // Read P bit from payload header (only at beginning of first partition).
-  if (payload_data_length > 0 && beginning_of_partition && partition_id == 0) {
+  if (beginning_of_partition && partition_id == 0) {
     parsed_payload->frame_type =
         (*payload_data & 0x01) ? kVideoFrameDelta : kVideoFrameKey;
   } else {
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_format_vp8.h b/webrtc/modules/rtp_rtcp/source/rtp_format_vp8.h
index 4b7a6a2..dab7921 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_format_vp8.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_format_vp8.h
@@ -51,12 +51,12 @@
   // Initialize with payload from encoder and fragmentation info.
   // The payload_data must be exactly one encoded VP8 frame.
   RtpPacketizerVp8(const RTPVideoHeaderVP8& hdr_info,
-                   int max_payload_len,
+                   size_t max_payload_len,
                    VP8PacketizerMode mode);
 
   // Initialize without fragmentation info. Mode kEqualSize will be used.
   // The payload_data must be exactly one encoded VP8 frame.
-  RtpPacketizerVp8(const RTPVideoHeaderVP8& hdr_info, int max_payload_len);
+  RtpPacketizerVp8(const RTPVideoHeaderVP8& hdr_info, size_t max_payload_len);
 
   virtual ~RtpPacketizerVp8();
 
@@ -88,10 +88,10 @@
 
  private:
   typedef struct {
-    int payload_start_pos;
-    int size;
+    size_t payload_start_pos;
+    size_t size;
     bool first_fragment;
-    int first_partition_ix;
+    size_t first_partition_ix;
   } InfoStruct;
   typedef std::queue<InfoStruct> InfoQueue;
   enum AggregationMode {
@@ -115,9 +115,9 @@
   static const int kYBit = 0x20;
 
   // Calculate size of next chunk to send. Returns 0 if none can be sent.
-  int CalcNextSize(int max_payload_len,
-                   int remaining_bytes,
-                   bool split_payload) const;
+  size_t CalcNextSize(size_t max_payload_len,
+                      size_t remaining_bytes,
+                      bool split_payload) const;
 
   // Calculate all packet sizes and load to packet info queue.
   int GeneratePackets();
@@ -140,9 +140,9 @@
                                 int* max_size);
 
   // Insert packet into packet queue.
-  void QueuePacket(int start_pos,
-                   int packet_size,
-                   int first_partition_in_packet,
+  void QueuePacket(size_t start_pos,
+                   size_t packet_size,
+                   size_t first_partition_in_packet,
                    bool start_on_new_fragment);
 
   // Write the payload header and copy the payload to the buffer.
@@ -150,47 +150,47 @@
   // and what to write in the header fields.
   int WriteHeaderAndPayload(const InfoStruct& packet_info,
                             uint8_t* buffer,
-                            int buffer_length) const;
+                            size_t buffer_length) const;
 
   // Write the X field and the appropriate extension fields to buffer.
   // The function returns the extension length (including X field), or -1
   // on error.
-  int WriteExtensionFields(uint8_t* buffer, int buffer_length) const;
+  int WriteExtensionFields(uint8_t* buffer, size_t buffer_length) const;
 
   // Set the I bit in the x_field, and write PictureID to the appropriate
   // position in buffer. The function returns 0 on success, -1 otherwise.
   int WritePictureIDFields(uint8_t* x_field,
                            uint8_t* buffer,
-                           int buffer_length,
-                           int* extension_length) const;
+                           size_t buffer_length,
+                           size_t* extension_length) const;
 
   // Set the L bit in the x_field, and write Tl0PicIdx to the appropriate
   // position in buffer. The function returns 0 on success, -1 otherwise.
   int WriteTl0PicIdxFields(uint8_t* x_field,
                            uint8_t* buffer,
-                           int buffer_length,
-                           int* extension_length) const;
+                           size_t buffer_length,
+                           size_t* extension_length) const;
 
   // Set the T and K bits in the x_field, and write TID, Y and KeyIdx to the
   // appropriate position in buffer. The function returns 0 on success,
   // -1 otherwise.
   int WriteTIDAndKeyIdxFields(uint8_t* x_field,
                               uint8_t* buffer,
-                              int buffer_length,
-                              int* extension_length) const;
+                              size_t buffer_length,
+                              size_t* extension_length) const;
 
   // Write the PictureID from codec_specific_info_ to buffer. One or two
   // bytes are written, depending on magnitude of PictureID. The function
   // returns the number of bytes written.
-  int WritePictureID(uint8_t* buffer, int buffer_length) const;
+  int WritePictureID(uint8_t* buffer, size_t buffer_length) const;
 
   // Calculate and return length (octets) of the variable header fields in
   // the next header (i.e., header length in addition to vp8_header_bytes_).
-  int PayloadDescriptorExtraLength() const;
+  size_t PayloadDescriptorExtraLength() const;
 
   // Calculate and return length (octets) of PictureID field in the next
   // header. Can be 0, 1, or 2.
-  int PictureIdLength() const;
+  size_t PictureIdLength() const;
 
   // Check whether each of the optional fields will be included in the header.
   bool XFieldPresent() const;
@@ -200,16 +200,16 @@
   bool PictureIdPresent() const { return (PictureIdLength() > 0); }
 
   const uint8_t* payload_data_;
-  int payload_size_;
+  size_t payload_size_;
   RTPFragmentationHeader part_info_;
-  const int vp8_fixed_payload_descriptor_bytes_;  // Length of VP8 payload
-                                                  // descriptors's fixed part.
+  const size_t vp8_fixed_payload_descriptor_bytes_;  // Length of VP8 payload
+                                                     // descriptors' fixed part.
   const AggregationMode aggr_mode_;
   const bool balance_;
   const bool separate_first_;
   const RTPVideoHeaderVP8 hdr_info_;
-  int num_partitions_;
-  const int max_payload_len_;
+  size_t num_partitions_;
+  const size_t max_payload_len_;
   InfoQueue packets_;
   bool packets_calculated_;
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.cc b/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.cc
index 549512b..a62f496 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.cc
@@ -35,25 +35,25 @@
   delete [] buffer_;
 }
 
-bool RtpFormatVp8TestHelper::Init(const int* partition_sizes,
-                                  int num_partitions) {
+bool RtpFormatVp8TestHelper::Init(const size_t* partition_sizes,
+                                  size_t num_partitions) {
   if (inited_) return false;
   fragmentation_ = new RTPFragmentationHeader;
   fragmentation_->VerifyAndAllocateFragmentationHeader(num_partitions);
   payload_size_ = 0;
   // Calculate sum payload size.
-  for (int p = 0; p < num_partitions; ++p) {
+  for (size_t p = 0; p < num_partitions; ++p) {
     payload_size_ += partition_sizes[p];
   }
   buffer_size_ = payload_size_ + 6;  // Add space for payload descriptor.
   payload_data_ = new uint8_t[payload_size_];
   buffer_ = new uint8_t[buffer_size_];
-  int j = 0;
+  size_t j = 0;
   // Loop through the partitions again.
-  for (int p = 0; p < num_partitions; ++p) {
+  for (size_t p = 0; p < num_partitions; ++p) {
     fragmentation_->fragmentationLength[p] = partition_sizes[p];
     fragmentation_->fragmentationOffset[p] = j;
-    for (int i = 0; i < partition_sizes[p]; ++i) {
+    for (size_t i = 0; i < partition_sizes[p]; ++i) {
       assert(j < payload_size_);
       payload_data_[j++] = p;  // Set the payload value to the partition index.
     }
@@ -65,14 +65,14 @@
 
 void RtpFormatVp8TestHelper::GetAllPacketsAndCheck(
     RtpPacketizerVp8* packetizer,
-    const int* expected_sizes,
+    const size_t* expected_sizes,
     const int* expected_part,
     const bool* expected_frag_start,
-    int expected_num_packets) {
+    size_t expected_num_packets) {
   ASSERT_TRUE(inited_);
   size_t send_bytes = 0;
   bool last = false;
-  for (int i = 0; i < expected_num_packets; ++i) {
+  for (size_t i = 0; i < expected_num_packets; ++i) {
     std::ostringstream ss;
     ss << "Checking packet " << i;
     SCOPED_TRACE(ss.str());
@@ -222,8 +222,8 @@
 
 // Verify that the payload (i.e., after the headers) of the packet stored in
 // buffer_ is identical to the expected (as found in data_ptr_).
-void RtpFormatVp8TestHelper::CheckPayload(int payload_end) {
-  for (int i = payload_start_; i < payload_end; ++i, ++data_ptr_)
+void RtpFormatVp8TestHelper::CheckPayload(size_t payload_end) {
+  for (size_t i = payload_start_; i < payload_end; ++i, ++data_ptr_)
     EXPECT_EQ(buffer_[i], *data_ptr_);
 }
 
@@ -236,8 +236,8 @@
 
 // Verify the contents of a packet. Check the length versus expected_bytes,
 // the header, payload, and "last" flag.
-void RtpFormatVp8TestHelper::CheckPacket(int send_bytes,
-                                         int expect_bytes,
+void RtpFormatVp8TestHelper::CheckPacket(size_t send_bytes,
+                                         size_t expect_bytes,
                                          bool last,
                                          bool frag_start) {
   EXPECT_EQ(expect_bytes, send_bytes);
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h b/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h
index 22e6803..2454fb7 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h
@@ -31,17 +31,17 @@
  public:
   explicit RtpFormatVp8TestHelper(const RTPVideoHeaderVP8* hdr);
   ~RtpFormatVp8TestHelper();
-  bool Init(const int* partition_sizes, int num_partitions);
+  bool Init(const size_t* partition_sizes, size_t num_partitions);
   void GetAllPacketsAndCheck(RtpPacketizerVp8* packetizer,
-                             const int* expected_sizes,
+                             const size_t* expected_sizes,
                              const int* expected_part,
                              const bool* expected_frag_start,
-                             int expected_num_packets);
+                             size_t expected_num_packets);
 
   uint8_t* payload_data() const { return payload_data_; }
-  int payload_size() const { return payload_size_; }
+  size_t payload_size() const { return payload_size_; }
   RTPFragmentationHeader* fragmentation() const { return fragmentation_; }
-  int buffer_size() const { return buffer_size_; }
+  size_t buffer_size() const { return buffer_size_; }
   void set_sloppy_partitioning(bool value) { sloppy_partitioning_ = value; }
 
  private:
@@ -49,9 +49,9 @@
   void CheckPictureID();
   void CheckTl0PicIdx();
   void CheckTIDAndKeyIdx();
-  void CheckPayload(int payload_end);
+  void CheckPayload(size_t payload_end);
   void CheckLast(bool last) const;
-  void CheckPacket(int send_bytes, int expect_bytes, bool last,
+  void CheckPacket(size_t send_bytes, size_t expect_bytes, bool last,
                    bool frag_start);
 
   uint8_t* payload_data_;
@@ -60,8 +60,8 @@
   RTPFragmentationHeader* fragmentation_;
   const RTPVideoHeaderVP8* hdr_info_;
   int payload_start_;
-  int payload_size_;
-  int buffer_size_;
+  size_t payload_size_;
+  size_t buffer_size_;
   bool sloppy_partitioning_;
   bool inited_;
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc
index 4382ac2..84b880d 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc
@@ -80,7 +80,7 @@
  protected:
   RtpPacketizerVp8Test() : helper_(NULL) {}
   virtual void TearDown() { delete helper_; }
-  bool Init(const int* partition_sizes, int num_partitions) {
+  bool Init(const size_t* partition_sizes, size_t num_partitions) {
     hdr_info_.pictureId = kNoPictureId;
     hdr_info_.nonReference = false;
     hdr_info_.temporalIdx = kNoTemporalIdx;
@@ -98,23 +98,23 @@
 };
 
 TEST_F(RtpPacketizerVp8Test, TestStrictMode) {
-  const int kSizeVector[] = {10, 8, 27};
-  const int kNumPartitions = sizeof(kSizeVector) / sizeof(kSizeVector[0]);
+  const size_t kSizeVector[] = {10, 8, 27};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector);
   ASSERT_TRUE(Init(kSizeVector, kNumPartitions));
 
   hdr_info_.pictureId = 200;  // > 0x7F should produce 2-byte PictureID.
-  const int kMaxSize = 13;
+  const size_t kMaxSize = 13;
   RtpPacketizerVp8 packetizer(hdr_info_, kMaxSize, kStrict);
   packetizer.SetPayloadData(helper_->payload_data(),
                             helper_->payload_size(),
                             helper_->fragmentation());
 
   // The expected sizes are obtained by running a verified good implementation.
-  const int kExpectedSizes[] = {9, 9, 12, 11, 11, 11, 10};
+  const size_t kExpectedSizes[] = {9, 9, 12, 11, 11, 11, 10};
   const int kExpectedPart[] = {0, 0, 1, 2, 2, 2, 2};
   const bool kExpectedFragStart[] = {true,  false, true, true,
                                      false, false, false};
-  const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]);
+  const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
 
@@ -126,22 +126,22 @@
 }
 
 TEST_F(RtpPacketizerVp8Test, TestAggregateMode) {
-  const int kSizeVector[] = {60, 10, 10};
-  const int kNumPartitions = sizeof(kSizeVector) / sizeof(kSizeVector[0]);
+  const size_t kSizeVector[] = {60, 10, 10};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector);
   ASSERT_TRUE(Init(kSizeVector, kNumPartitions));
 
   hdr_info_.pictureId = 20;  // <= 0x7F should produce 1-byte PictureID.
-  const int kMaxSize = 25;
+  const size_t kMaxSize = 25;
   RtpPacketizerVp8 packetizer(hdr_info_, kMaxSize, kAggregate);
   packetizer.SetPayloadData(helper_->payload_data(),
                             helper_->payload_size(),
                             helper_->fragmentation());
 
   // The expected sizes are obtained by running a verified good implementation.
-  const int kExpectedSizes[] = {23, 23, 23, 23};
+  const size_t kExpectedSizes[] = {23, 23, 23, 23};
   const int kExpectedPart[] = {0, 0, 0, 1};
   const bool kExpectedFragStart[] = {true, false, false, true};
-  const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]);
+  const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
 
@@ -153,22 +153,22 @@
 }
 
 TEST_F(RtpPacketizerVp8Test, TestAggregateModeManyPartitions1) {
-  const int kSizeVector[] = {1600, 200, 200, 200, 200, 200, 200, 200, 200};
-  const int kNumPartitions = sizeof(kSizeVector) / sizeof(kSizeVector[0]);
+  const size_t kSizeVector[] = {1600, 200, 200, 200, 200, 200, 200, 200, 200};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector);
   ASSERT_TRUE(Init(kSizeVector, kNumPartitions));
 
   hdr_info_.pictureId = 20;  // <= 0x7F should produce 1-byte PictureID.
-  const int kMaxSize = 1500;
+  const size_t kMaxSize = 1500;
   RtpPacketizerVp8 packetizer(hdr_info_, kMaxSize, kAggregate);
   packetizer.SetPayloadData(helper_->payload_data(),
                             helper_->payload_size(),
                             helper_->fragmentation());
 
   // The expected sizes are obtained by running a verified good implementation.
-  const int kExpectedSizes[] = {803, 803, 803, 803};
+  const size_t kExpectedSizes[] = {803, 803, 803, 803};
   const int kExpectedPart[] = {0, 0, 1, 5};
   const bool kExpectedFragStart[] = {true, false, true, true};
-  const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]);
+  const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
 
@@ -180,22 +180,22 @@
 }
 
 TEST_F(RtpPacketizerVp8Test, TestAggregateModeManyPartitions2) {
-  const int kSizeVector[] = {1599, 200, 200, 200, 1600, 200, 200, 200, 200};
-  const int kNumPartitions = sizeof(kSizeVector) / sizeof(kSizeVector[0]);
+  const size_t kSizeVector[] = {1599, 200, 200, 200, 1600, 200, 200, 200, 200};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector);
   ASSERT_TRUE(Init(kSizeVector, kNumPartitions));
 
   hdr_info_.pictureId = 20;  // <= 0x7F should produce 1-byte PictureID.
-  const int kMaxSize = 1500;
+  const size_t kMaxSize = 1500;
   RtpPacketizerVp8 packetizer(hdr_info_, kMaxSize, kAggregate);
   packetizer.SetPayloadData(helper_->payload_data(),
                             helper_->payload_size(),
                             helper_->fragmentation());
 
   // The expected sizes are obtained by running a verified good implementation.
-  const int kExpectedSizes[] = {803, 802, 603, 803, 803, 803};
+  const size_t kExpectedSizes[] = {803, 802, 603, 803, 803, 803};
   const int kExpectedPart[] = {0, 0, 1, 4, 4, 5};
   const bool kExpectedFragStart[] = {true, false, true, true, false, true};
-  const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]);
+  const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
 
@@ -207,22 +207,22 @@
 }
 
 TEST_F(RtpPacketizerVp8Test, TestAggregateModeTwoLargePartitions) {
-  const int kSizeVector[] = {1654, 2268};
-  const int kNumPartitions = sizeof(kSizeVector) / sizeof(kSizeVector[0]);
+  const size_t kSizeVector[] = {1654, 2268};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector);
   ASSERT_TRUE(Init(kSizeVector, kNumPartitions));
 
   hdr_info_.pictureId = 20;  // <= 0x7F should produce 1-byte PictureID.
-  const int kMaxSize = 1460;
+  const size_t kMaxSize = 1460;
   RtpPacketizerVp8 packetizer(hdr_info_, kMaxSize, kAggregate);
   packetizer.SetPayloadData(helper_->payload_data(),
                             helper_->payload_size(),
                             helper_->fragmentation());
 
   // The expected sizes are obtained by running a verified good implementation.
-  const int kExpectedSizes[] = {830, 830, 1137, 1137};
+  const size_t kExpectedSizes[] = {830, 830, 1137, 1137};
   const int kExpectedPart[] = {0, 0, 1, 1};
   const bool kExpectedFragStart[] = {true, false, true, false};
-  const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]);
+  const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
 
@@ -235,22 +235,22 @@
 
 // Verify that EqualSize mode is forced if fragmentation info is missing.
 TEST_F(RtpPacketizerVp8Test, TestEqualSizeModeFallback) {
-  const int kSizeVector[] = {10, 10, 10};
-  const int kNumPartitions = sizeof(kSizeVector) / sizeof(kSizeVector[0]);
+  const size_t kSizeVector[] = {10, 10, 10};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector);
   ASSERT_TRUE(Init(kSizeVector, kNumPartitions));
 
-  hdr_info_.pictureId = 200;  // > 0x7F should produce 2-byte PictureID
-  const int kMaxSize = 12;    // Small enough to produce 4 packets.
+  hdr_info_.pictureId = 200;   // > 0x7F should produce 2-byte PictureID
+  const size_t kMaxSize = 12;  // Small enough to produce 4 packets.
   RtpPacketizerVp8 packetizer(hdr_info_, kMaxSize);
   packetizer.SetPayloadData(
       helper_->payload_data(), helper_->payload_size(), NULL);
 
   // Expecting three full packets, and one with the remainder.
-  const int kExpectedSizes[] = {12, 11, 12, 11};
+  const size_t kExpectedSizes[] = {12, 11, 12, 11};
   const int kExpectedPart[] = {0, 0, 0, 0};  // Always 0 for equal size mode.
   // Frag start only true for first packet in equal size mode.
   const bool kExpectedFragStart[] = {true, false, false, false};
-  const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]);
+  const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
 
@@ -264,22 +264,22 @@
 
 // Verify that non-reference bit is set. EqualSize mode fallback is expected.
 TEST_F(RtpPacketizerVp8Test, TestNonReferenceBit) {
-  const int kSizeVector[] = {10, 10, 10};
-  const int kNumPartitions = sizeof(kSizeVector) / sizeof(kSizeVector[0]);
+  const size_t kSizeVector[] = {10, 10, 10};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector);
   ASSERT_TRUE(Init(kSizeVector, kNumPartitions));
 
   hdr_info_.nonReference = true;
-  const int kMaxSize = 25;  // Small enough to produce two packets.
+  const size_t kMaxSize = 25;  // Small enough to produce two packets.
   RtpPacketizerVp8 packetizer(hdr_info_, kMaxSize);
   packetizer.SetPayloadData(
       helper_->payload_data(), helper_->payload_size(), NULL);
 
   // EqualSize mode => First packet full; other not.
-  const int kExpectedSizes[] = {16, 16};
+  const size_t kExpectedSizes[] = {16, 16};
   const int kExpectedPart[] = {0, 0};  // Always 0 for equal size mode.
   // Frag start only true for first packet in equal size mode.
   const bool kExpectedFragStart[] = {true, false};
-  const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]);
+  const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
 
@@ -293,25 +293,25 @@
 
 // Verify Tl0PicIdx and TID fields, and layerSync bit.
 TEST_F(RtpPacketizerVp8Test, TestTl0PicIdxAndTID) {
-  const int kSizeVector[] = {10, 10, 10};
-  const int kNumPartitions = sizeof(kSizeVector) / sizeof(kSizeVector[0]);
+  const size_t kSizeVector[] = {10, 10, 10};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector);
   ASSERT_TRUE(Init(kSizeVector, kNumPartitions));
 
   hdr_info_.tl0PicIdx = 117;
   hdr_info_.temporalIdx = 2;
   hdr_info_.layerSync = true;
   // kMaxSize is only limited by allocated buffer size.
-  const int kMaxSize = helper_->buffer_size();
+  const size_t kMaxSize = helper_->buffer_size();
   RtpPacketizerVp8 packetizer(hdr_info_, kMaxSize, kAggregate);
   packetizer.SetPayloadData(helper_->payload_data(),
                             helper_->payload_size(),
                             helper_->fragmentation());
 
   // Expect one single packet of payload_size() + 4 bytes header.
-  const int kExpectedSizes[1] = {helper_->payload_size() + 4};
+  const size_t kExpectedSizes[1] = {helper_->payload_size() + 4};
   const int kExpectedPart[1] = {0};  // Packet starts with partition 0.
   const bool kExpectedFragStart[1] = {true};
-  const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]);
+  const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
 
@@ -324,23 +324,23 @@
 
 // Verify KeyIdx field.
 TEST_F(RtpPacketizerVp8Test, TestKeyIdx) {
-  const int kSizeVector[] = {10, 10, 10};
-  const int kNumPartitions = sizeof(kSizeVector) / sizeof(kSizeVector[0]);
+  const size_t kSizeVector[] = {10, 10, 10};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector);
   ASSERT_TRUE(Init(kSizeVector, kNumPartitions));
 
   hdr_info_.keyIdx = 17;
   // kMaxSize is only limited by allocated buffer size.
-  const int kMaxSize = helper_->buffer_size();
+  const size_t kMaxSize = helper_->buffer_size();
   RtpPacketizerVp8 packetizer(hdr_info_, kMaxSize, kAggregate);
   packetizer.SetPayloadData(helper_->payload_data(),
                             helper_->payload_size(),
                             helper_->fragmentation());
 
   // Expect one single packet of payload_size() + 3 bytes header.
-  const int kExpectedSizes[1] = {helper_->payload_size() + 3};
+  const size_t kExpectedSizes[1] = {helper_->payload_size() + 3};
   const int kExpectedPart[1] = {0};  // Packet starts with partition 0.
   const bool kExpectedFragStart[1] = {true};
-  const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]);
+  const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
 
@@ -353,24 +353,24 @@
 
 // Verify TID field and KeyIdx field in combination.
 TEST_F(RtpPacketizerVp8Test, TestTIDAndKeyIdx) {
-  const int kSizeVector[] = {10, 10, 10};
-  const int kNumPartitions = sizeof(kSizeVector) / sizeof(kSizeVector[0]);
+  const size_t kSizeVector[] = {10, 10, 10};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector);
   ASSERT_TRUE(Init(kSizeVector, kNumPartitions));
 
   hdr_info_.temporalIdx = 1;
   hdr_info_.keyIdx = 5;
   // kMaxSize is only limited by allocated buffer size.
-  const int kMaxSize = helper_->buffer_size();
+  const size_t kMaxSize = helper_->buffer_size();
   RtpPacketizerVp8 packetizer(hdr_info_, kMaxSize, kAggregate);
   packetizer.SetPayloadData(helper_->payload_data(),
                             helper_->payload_size(),
                             helper_->fragmentation());
 
   // Expect one single packet of payload_size() + 3 bytes header.
-  const int kExpectedSizes[1] = {helper_->payload_size() + 3};
+  const size_t kExpectedSizes[1] = {helper_->payload_size() + 3};
   const int kExpectedPart[1] = {0};  // Packet starts with partition 0.
   const bool kExpectedFragStart[1] = {true};
-  const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]);
+  const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
   CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_header_extension.cc b/webrtc/modules/rtp_rtcp/source/rtp_header_extension.cc
index 9a1836e..a19eeaa 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_header_extension.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_header_extension.cc
@@ -105,9 +105,9 @@
   return -1;
 }
 
-uint16_t RtpHeaderExtensionMap::GetTotalLengthInBytes() const {
+size_t RtpHeaderExtensionMap::GetTotalLengthInBytes() const {
   // Get length for each extension block.
-  uint16_t length = 0;
+  size_t length = 0;
   std::map<uint8_t, HeaderExtension*>::const_iterator it =
       extensionMap_.begin();
   while (it != extensionMap_.end()) {
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_header_extension.h b/webrtc/modules/rtp_rtcp/source/rtp_header_extension.h
index edffe8a..335d0a1 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_header_extension.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_header_extension.h
@@ -68,7 +68,7 @@
 
   int32_t GetId(const RTPExtensionType type, uint8_t* id) const;
 
-  uint16_t GetTotalLengthInBytes() const;
+  size_t GetTotalLengthInBytes() const;
 
   int32_t GetLengthUntilBlockStartInBytes(const RTPExtensionType type) const;
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_header_extension_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_header_extension_unittest.cc
index 90d3f64..d8387e8 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_header_extension_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_header_extension_unittest.cc
@@ -59,7 +59,7 @@
 }
 
 TEST_F(RtpHeaderExtensionTest, GetTotalLength) {
-  EXPECT_EQ(0, map_.GetTotalLengthInBytes());
+  EXPECT_EQ(0u, map_.GetTotalLengthInBytes());
   EXPECT_EQ(0, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
   EXPECT_EQ(kRtpOneByteHeaderLength + kTransmissionTimeOffsetLength,
             map_.GetTotalLengthInBytes());
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_packet_history.cc b/webrtc/modules/rtp_rtcp/source/rtp_packet_history.cc
index e3515f4..2546ac0 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_packet_history.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_packet_history.cc
@@ -94,7 +94,7 @@
 }
 
 // private, lock should already be taken
-void RTPPacketHistory::VerifyAndAllocatePacketLength(uint16_t packet_length) {
+void RTPPacketHistory::VerifyAndAllocatePacketLength(size_t packet_length) {
   assert(packet_length > 0);
   if (!store_) {
     return;
@@ -112,8 +112,8 @@
 }
 
 int32_t RTPPacketHistory::PutRTPPacket(const uint8_t* packet,
-                                       uint16_t packet_length,
-                                       uint16_t max_packet_length,
+                                       size_t packet_length,
+                                       size_t max_packet_length,
                                        int64_t capture_time_ms,
                                        StorageType type) {
   if (type == kDontStore) {
@@ -169,7 +169,7 @@
     return false;
   }
 
-  uint16_t length = stored_lengths_.at(index);
+  size_t length = stored_lengths_.at(index);
   if (length == 0 || length > max_packet_length_) {
     // Invalid length.
     return false;
@@ -181,7 +181,7 @@
                                                uint32_t min_elapsed_time_ms,
                                                bool retransmit,
                                                uint8_t* packet,
-                                               uint16_t* packet_length,
+                                               size_t* packet_length,
                                                int64_t* stored_time_ms) {
   assert(*packet_length >= max_packet_length_);
   CriticalSectionScoped cs(critsect_);
@@ -196,7 +196,7 @@
     return false;
   }
 
-  uint16_t length = stored_lengths_.at(index);
+  size_t length = stored_lengths_.at(index);
   assert(length <= max_packet_length_);
   if (length == 0) {
     LOG(LS_WARNING) << "No match for getting seqNum " << sequence_number
@@ -223,10 +223,10 @@
 
 void RTPPacketHistory::GetPacket(int index,
                                  uint8_t* packet,
-                                 uint16_t* packet_length,
+                                 size_t* packet_length,
                                  int64_t* stored_time_ms) const {
   // Get packet.
-  uint16_t length = stored_lengths_.at(index);
+  size_t length = stored_lengths_.at(index);
   std::vector<std::vector<uint8_t> >::const_iterator it_found_packet =
       stored_packets_.begin() + index;
   std::copy(it_found_packet->begin(), it_found_packet->begin() + length,
@@ -236,7 +236,7 @@
 }
 
 bool RTPPacketHistory::GetBestFittingPacket(uint8_t* packet,
-                                            uint16_t* packet_length,
+                                            size_t* packet_length,
                                             int64_t* stored_time_ms) {
   CriticalSectionScoped cs(critsect_);
   if (!store_)
@@ -283,22 +283,21 @@
   return false;
 }
 
-int RTPPacketHistory::FindBestFittingPacket(uint16_t size) const {
+int RTPPacketHistory::FindBestFittingPacket(size_t size) const {
   if (size < kMinPacketRequestBytes || stored_lengths_.empty())
     return -1;
-  int min_diff = -1;
-  size_t best_index = 0;
+  size_t min_diff = std::numeric_limits<size_t>::max();
+  int best_index = -1;  // Returned unchanged if we don't find anything.
   for (size_t i = 0; i < stored_lengths_.size(); ++i) {
     if (stored_lengths_[i] == 0)
       continue;
-    int diff = abs(stored_lengths_[i] - size);
-    if (min_diff < 0 || diff < min_diff) {
+    size_t diff = (stored_lengths_[i] > size) ?
+        (stored_lengths_[i] - size) : (size - stored_lengths_[i]);
+    if (diff < min_diff) {
       min_diff = diff;
-      best_index = i;
+      best_index = static_cast<int>(i);
     }
   }
-  if (min_diff < 0)
-    return -1;
   return best_index;
 }
 }  // namespace webrtc
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_packet_history.h b/webrtc/modules/rtp_rtcp/source/rtp_packet_history.h
index 253f6d0..eea3f12 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_packet_history.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_packet_history.h
@@ -36,8 +36,8 @@
 
   // Stores RTP packet.
   int32_t PutRTPPacket(const uint8_t* packet,
-                       uint16_t packet_length,
-                       uint16_t max_packet_length,
+                       size_t packet_length,
+                       size_t max_packet_length,
                        int64_t capture_time_ms,
                        StorageType type);
 
@@ -56,33 +56,33 @@
                                uint32_t min_elapsed_time_ms,
                                bool retransmit,
                                uint8_t* packet,
-                               uint16_t* packet_length,
+                               size_t* packet_length,
                                int64_t* stored_time_ms);
 
-  bool GetBestFittingPacket(uint8_t* packet, uint16_t* packet_length,
+  bool GetBestFittingPacket(uint8_t* packet, size_t* packet_length,
                             int64_t* stored_time_ms);
 
   bool HasRTPPacket(uint16_t sequence_number) const;
 
  private:
-  void GetPacket(int index, uint8_t* packet, uint16_t* packet_length,
+  void GetPacket(int index, uint8_t* packet, size_t* packet_length,
                  int64_t* stored_time_ms) const;
   void Allocate(uint16_t number_to_store) EXCLUSIVE_LOCKS_REQUIRED(*critsect_);
   void Free() EXCLUSIVE_LOCKS_REQUIRED(*critsect_);
-  void VerifyAndAllocatePacketLength(uint16_t packet_length);
+  void VerifyAndAllocatePacketLength(size_t packet_length);
   bool FindSeqNum(uint16_t sequence_number, int32_t* index) const;
-  int FindBestFittingPacket(uint16_t size) const;
+  int FindBestFittingPacket(size_t size) const;
 
  private:
   Clock* clock_;
   CriticalSectionWrapper* critsect_;
   bool store_;
   uint32_t prev_index_;
-  uint16_t max_packet_length_;
+  size_t max_packet_length_;
 
   std::vector<std::vector<uint8_t> > stored_packets_;
   std::vector<uint16_t> stored_seq_nums_;
-  std::vector<uint16_t> stored_lengths_;
+  std::vector<size_t> stored_lengths_;
   std::vector<int64_t> stored_times_;
   std::vector<int64_t> stored_send_times_;
   std::vector<StorageType> stored_types_;
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_packet_history_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_packet_history_unittest.cc
index 7eb22ff..76798b6 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_packet_history_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_packet_history_unittest.cc
@@ -40,7 +40,7 @@
   uint8_t packet_out_[kMaxPacketLength];
 
   void CreateRtpPacket(uint16_t seq_num, uint32_t ssrc, uint8_t payload,
-      uint32_t timestamp, uint8_t* array, uint16_t* cur_pos) {
+      uint32_t timestamp, uint8_t* array, size_t* cur_pos) {
     array[(*cur_pos)++] = 0x80;
     array[(*cur_pos)++] = payload;
     array[(*cur_pos)++] = seq_num >> 8;
@@ -66,7 +66,7 @@
 
 TEST_F(RtpPacketHistoryTest, NoStoreStatus) {
   EXPECT_FALSE(hist_->StorePackets());
-  uint16_t len = 0;
+  size_t len = 0;
   int64_t capture_time_ms = fake_clock_.TimeInMilliseconds();
   CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len);
   EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength,
@@ -80,7 +80,7 @@
 
 TEST_F(RtpPacketHistoryTest, DontStore) {
   hist_->SetStorePacketsStatus(true, 10);
-  uint16_t len = 0;
+  size_t len = 0;
   int64_t capture_time_ms = fake_clock_.TimeInMilliseconds();
   CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len);
   EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength,
@@ -105,7 +105,7 @@
 
 TEST_F(RtpPacketHistoryTest, GetRtpPacket_NotStored) {
   hist_->SetStorePacketsStatus(true, 10);
-  uint16_t len = kMaxPacketLength;
+  size_t len = kMaxPacketLength;
   int64_t time;
   EXPECT_FALSE(hist_->GetPacketAndSetSendTime(0, 0, false, packet_, &len,
                                               &time));
@@ -113,7 +113,7 @@
 
 TEST_F(RtpPacketHistoryTest, PutRtpPacket) {
   hist_->SetStorePacketsStatus(true, 10);
-  uint16_t len = 0;
+  size_t len = 0;
   CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len);
 
   EXPECT_FALSE(hist_->HasRTPPacket(kSeqNum));
@@ -125,52 +125,52 @@
 
 TEST_F(RtpPacketHistoryTest, GetRtpPacket) {
   hist_->SetStorePacketsStatus(true, 10);
-  uint16_t len = 0;
+  size_t len = 0;
   int64_t capture_time_ms = 1;
   CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len);
   EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength,
                                    capture_time_ms, kAllowRetransmission));
 
-  uint16_t len_out = kMaxPacketLength;
+  size_t len_out = kMaxPacketLength;
   int64_t time;
   EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_,
                                              &len_out, &time));
   EXPECT_EQ(len, len_out);
   EXPECT_EQ(capture_time_ms, time);
-  for (int i = 0; i < len; i++)  {
+  for (size_t i = 0; i < len; i++)  {
     EXPECT_EQ(packet_[i], packet_out_[i]);
   }
 }
 
 TEST_F(RtpPacketHistoryTest, NoCaptureTime) {
   hist_->SetStorePacketsStatus(true, 10);
-  uint16_t len = 0;
+  size_t len = 0;
   fake_clock_.AdvanceTimeMilliseconds(1);
   int64_t capture_time_ms = fake_clock_.TimeInMilliseconds();
   CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len);
   EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength,
                                    -1, kAllowRetransmission));
 
-  uint16_t len_out = kMaxPacketLength;
+  size_t len_out = kMaxPacketLength;
   int64_t time;
   EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_,
                                              &len_out, &time));
   EXPECT_EQ(len, len_out);
   EXPECT_EQ(capture_time_ms, time);
-  for (int i = 0; i < len; i++)  {
+  for (size_t i = 0; i < len; i++)  {
     EXPECT_EQ(packet_[i], packet_out_[i]);
   }
 }
 
 TEST_F(RtpPacketHistoryTest, DontRetransmit) {
   hist_->SetStorePacketsStatus(true, 10);
-  uint16_t len = 0;
+  size_t len = 0;
   int64_t capture_time_ms = fake_clock_.TimeInMilliseconds();
   CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len);
   EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength,
                                    capture_time_ms, kDontRetransmit));
 
-  uint16_t len_out = kMaxPacketLength;
+  size_t len_out = kMaxPacketLength;
   int64_t time;
   EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_,
                                              &len_out, &time));
@@ -180,7 +180,7 @@
 
 TEST_F(RtpPacketHistoryTest, MinResendTime) {
   hist_->SetStorePacketsStatus(true, 10);
-  uint16_t len = 0;
+  size_t len = 0;
   int64_t capture_time_ms = fake_clock_.TimeInMilliseconds();
   CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len);
   EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength,
@@ -195,7 +195,7 @@
   len = kMaxPacketLength;
   EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 100, false, packet_, &len,
                                              &time));
-  EXPECT_GT(len, 0);
+  EXPECT_GT(len, 0u);
   EXPECT_EQ(capture_time_ms, time);
 
   // Time has not elapsed. Packet should be found, but no bytes copied.
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc
index ec05a73..6073016 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc
@@ -242,7 +242,7 @@
 
 bool RTPPayloadRegistry::RestoreOriginalPacket(uint8_t** restored_packet,
                                                const uint8_t* packet,
-                                               int* packet_length,
+                                               size_t* packet_length,
                                                uint32_t original_ssrc,
                                                const RTPHeader& header) const {
   if (kRtxHeaderSize + header.headerLength > *packet_length) {
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.cc b/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.cc
index 05eefbe..7e37528 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.cc
@@ -184,7 +184,7 @@
                                          const PayloadUnion& specific_payload,
                                          bool is_red,
                                          const uint8_t* payload,
-                                         uint16_t payload_length,
+                                         size_t payload_length,
                                          int64_t timestamp_ms,
                                          bool is_first_packet) {
   TRACE_EVENT2("webrtc_rtp", "Audio::ParseRtp",
@@ -288,7 +288,7 @@
 int32_t RTPReceiverAudio::ParseAudioCodecSpecific(
     WebRtcRTPHeader* rtp_header,
     const uint8_t* payload_data,
-    uint16_t payload_length,
+    size_t payload_length,
     const AudioPayload& audio_specific,
     bool is_red) {
 
@@ -311,13 +311,13 @@
     if (payload_length % 4 != 0) {
       return -1;
     }
-    uint8_t number_of_events = payload_length / 4;
+    size_t number_of_events = payload_length / 4;
 
     // sanity
     if (number_of_events >= MAX_NUMBER_OF_PARALLEL_TELEPHONE_EVENTS) {
       number_of_events = MAX_NUMBER_OF_PARALLEL_TELEPHONE_EVENTS;
     }
-    for (int n = 0; n < number_of_events; ++n) {
+    for (size_t n = 0; n < number_of_events; ++n) {
       bool end = (payload_data[(4 * n) + 1] & 0x80) ? true : false;
 
       std::set<uint8_t>::iterator event =
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h b/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h
index 4fb7256..2c6af68 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h
@@ -53,13 +53,13 @@
                       uint32_t* frequency,
                       bool* cng_payload_type_has_changed);
 
-  int32_t ParseRtpPacket(WebRtcRTPHeader* rtp_header,
-                         const PayloadUnion& specific_payload,
-                         bool is_red,
-                         const uint8_t* packet,
-                         uint16_t packet_length,
-                         int64_t timestamp_ms,
-                         bool is_first_packet);
+  virtual int32_t ParseRtpPacket(WebRtcRTPHeader* rtp_header,
+                                 const PayloadUnion& specific_payload,
+                                 bool is_red,
+                                 const uint8_t* packet,
+                                 size_t payload_length,
+                                 int64_t timestamp_ms,
+                                 bool is_first_packet) OVERRIDE;
 
   int GetPayloadTypeFrequency() const OVERRIDE;
 
@@ -104,7 +104,7 @@
   int32_t ParseAudioCodecSpecific(
       WebRtcRTPHeader* rtp_header,
       const uint8_t* payload_data,
-      uint16_t payload_length,
+      size_t payload_length,
       const AudioPayload& audio_specific,
       bool is_red);
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.cc b/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.cc
index 22fae10..1cbc2ac 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.cc
@@ -163,12 +163,9 @@
 bool RtpReceiverImpl::IncomingRtpPacket(
   const RTPHeader& rtp_header,
   const uint8_t* payload,
-  int payload_length,
+  size_t payload_length,
   PayloadUnion payload_specific,
   bool in_order) {
-  // Sanity check.
-  assert(payload_length >= 0);
-
   // Trigger our callbacks.
   CheckSSRCChanged(rtp_header);
 
@@ -198,7 +195,7 @@
   webrtc_rtp_header.header = rtp_header;
   CheckCSRC(webrtc_rtp_header);
 
-  uint16_t payload_data_length = payload_length - rtp_header.paddingLength;
+  size_t payload_data_length = payload_length - rtp_header.paddingLength;
 
   bool is_first_packet_in_frame = false;
   {
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.h b/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.h
index 6068811..9e58b1a 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.h
@@ -46,7 +46,7 @@
   virtual bool IncomingRtpPacket(
       const RTPHeader& rtp_header,
       const uint8_t* payload,
-      int payload_length,
+      size_t payload_length,
       PayloadUnion payload_specific,
       bool in_order) OVERRIDE;
 
@@ -88,7 +88,7 @@
 
   scoped_ptr<CriticalSectionWrapper> critical_section_rtp_receiver_;
   int64_t last_receive_time_;
-  uint16_t last_received_payload_length_;
+  size_t last_received_payload_length_;
 
   // SSRCs.
   uint32_t ssrc_;
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h b/webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h
index 09c9b6f..0eb23e5 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h
@@ -43,7 +43,7 @@
                                  const PayloadUnion& specific_payload,
                                  bool is_red,
                                  const uint8_t* payload,
-                                 uint16_t payload_length,
+                                 size_t payload_length,
                                  int64_t timestamp_ms,
                                  bool is_first_packet) = 0;
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.cc b/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.cc
index 6f6d647..6fe3e1d 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.cc
@@ -51,7 +51,7 @@
                                          const PayloadUnion& specific_payload,
                                          bool is_red,
                                          const uint8_t* payload,
-                                         uint16_t payload_length,
+                                         size_t payload_length,
                                          int64_t timestamp_ms,
                                          bool is_first_packet) {
   TRACE_EVENT2("webrtc_rtp",
@@ -62,7 +62,7 @@
                rtp_header->header.timestamp);
   rtp_header->type.Video.codec = specific_payload.Video.videoCodecType;
 
-  const uint16_t payload_data_length =
+  const size_t payload_data_length =
       payload_length - rtp_header->header.paddingLength;
 
   if (payload == NULL || payload_data_length == 0) {
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h b/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h
index 8fe4acb..177f303 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h
@@ -30,7 +30,7 @@
                                  const PayloadUnion& specific_payload,
                                  bool is_red,
                                  const uint8_t* packet,
-                                 uint16_t packet_length,
+                                 size_t packet_length,
                                  int64_t timestamp,
                                  bool is_first_packet) OVERRIDE;
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
index 6446cb7..db10956 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
@@ -259,7 +259,7 @@
 
 int32_t ModuleRtpRtcpImpl::IncomingRtcpPacket(
     const uint8_t* rtcp_packet,
-    const uint16_t length) {
+    const size_t length) {
   // Allow receive of non-compound RTCP packets.
   RTCPUtility::RTCPParserV2 rtcp_parser(rtcp_packet, length, true);
 
@@ -504,7 +504,7 @@
     uint32_t time_stamp,
     int64_t capture_time_ms,
     const uint8_t* payload_data,
-    uint32_t payload_size,
+    size_t payload_size,
     const RTPFragmentationHeader* fragmentation,
     const RTPVideoHeader* rtp_video_hdr) {
   rtcp_sender_.SetLastRtpTime(time_stamp, capture_time_ms);
@@ -603,7 +603,7 @@
   return true;
 }
 
-int ModuleRtpRtcpImpl::TimeToSendPadding(int bytes) {
+size_t ModuleRtpRtcpImpl::TimeToSendPadding(size_t bytes) {
   if (!IsDefaultModule()) {
     // Don't send from default module.
     return rtp_sender_.TimeToSendPadding(bytes);
@@ -816,7 +816,7 @@
 }
 
 int32_t ModuleRtpRtcpImpl::DataCountersRTP(
-    uint32_t* bytes_sent,
+    size_t* bytes_sent,
     uint32_t* packets_sent) const {
   StreamDataCounters rtp_stats;
   StreamDataCounters rtx_stats;
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h
index 4975812..1b7db9f 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h
@@ -40,7 +40,7 @@
 
   // Called when we receive an RTCP packet.
   virtual int32_t IncomingRtcpPacket(const uint8_t* incoming_packet,
-                                     uint16_t incoming_packet_length) OVERRIDE;
+                                     size_t incoming_packet_length) OVERRIDE;
 
   virtual void SetRemoteSSRC(const uint32_t ssrc) OVERRIDE;
 
@@ -120,7 +120,7 @@
       const uint32_t time_stamp,
       int64_t capture_time_ms,
       const uint8_t* payload_data,
-      const uint32_t payload_size,
+      const size_t payload_size,
       const RTPFragmentationHeader* fragmentation = NULL,
       const RTPVideoHeader* rtp_video_hdr = NULL) OVERRIDE;
 
@@ -130,7 +130,7 @@
                                 bool retransmission) OVERRIDE;
   // Returns the number of padding bytes actually sent, which can be more or
   // less than |bytes|.
-  virtual int TimeToSendPadding(int bytes) OVERRIDE;
+  virtual size_t TimeToSendPadding(size_t bytes) OVERRIDE;
 
   virtual bool GetSendSideDelay(int* avg_send_delay_ms,
                                 int* max_send_delay_ms) const OVERRIDE;
@@ -179,7 +179,7 @@
   virtual int32_t ResetSendDataCountersRTP() OVERRIDE;
 
   // Statistics of the amount of data sent and received.
-  virtual int32_t DataCountersRTP(uint32_t* bytes_sent,
+  virtual int32_t DataCountersRTP(size_t* bytes_sent,
                                   uint32_t* packets_sent) const OVERRIDE;
 
   // Get received RTCP report, sender info.
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc
index 24ff227..bf6ab39 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc
@@ -67,17 +67,17 @@
     clock_ = clock;
     delay_ms_ = delay_ms;
   }
-  virtual int SendPacket(int /*ch*/, const void* data, int len) OVERRIDE {
+  virtual int SendPacket(int /*ch*/, const void* data, size_t len) OVERRIDE {
     RTPHeader header;
     scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
-    EXPECT_TRUE(parser->Parse(static_cast<const uint8_t*>(data),
-                              static_cast<size_t>(len),
-                              &header));
+    EXPECT_TRUE(parser->Parse(static_cast<const uint8_t*>(data), len, &header));
     ++rtp_packets_sent_;
     last_rtp_header_ = header;
-    return len;
+    return static_cast<int>(len);
   }
-  virtual int SendRTCPPacket(int /*ch*/, const void *data, int len) OVERRIDE {
+  virtual int SendRTCPPacket(int /*ch*/,
+                             const void *data,
+                             size_t len) OVERRIDE {
     test::RtcpPacketParser parser;
     parser.Parse(static_cast<const uint8_t*>(data), len);
     last_nack_list_ = parser.nack_item()->last_nack_list();
@@ -88,7 +88,7 @@
     EXPECT_TRUE(receiver_ != NULL);
     EXPECT_EQ(0, receiver_->IncomingRtcpPacket(
         static_cast<const uint8_t*>(data), len));
-    return len;
+    return static_cast<int>(len);
   }
   ModuleRtpRtcpImpl* receiver_;
   SimulatedClock* clock_;
@@ -398,7 +398,9 @@
  public:
   void ResetCounters() { bytes_received_.clear(); }
 
-  virtual int SendPacket(int channel, const void* data, int length) OVERRIDE {
+  virtual int SendPacket(int channel,
+                         const void* data,
+                         size_t length) OVERRIDE {
     RTPHeader header;
     scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
     EXPECT_TRUE(parser->Parse(static_cast<const uint8_t*>(data),
@@ -406,13 +408,13 @@
                               &header));
     bytes_received_[header.ssrc] += length;
     ++packets_received_[header.ssrc];
-    return length;
+    return static_cast<int>(length);
   }
 
   virtual int SendRTCPPacket(int channel,
                              const void* data,
-                             int length) OVERRIDE {
-    return length;
+                             size_t length) OVERRIDE {
+    return static_cast<int>(length);
   }
 
   int GetPacketsReceived(uint32_t ssrc) const {
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc
index 677f3fc..38ac859 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc
@@ -22,7 +22,7 @@
 namespace webrtc {
 
 // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP.
-const int kMaxPaddingLength = 224;
+const size_t kMaxPaddingLength = 224;
 const int kSendSideDelayWindowMs = 1000;
 
 namespace {
@@ -272,7 +272,7 @@
   return rtp_header_extension_map_.Deregister(type);
 }
 
-uint16_t RTPSender::RtpHeaderExtensionTotalLength() const {
+size_t RTPSender::RtpHeaderExtensionTotalLength() const {
   CriticalSectionScoped cs(send_critsect_);
   return rtp_header_extension_map_.GetTotalLengthInBytes();
 }
@@ -355,7 +355,7 @@
 }
 
 int32_t RTPSender::SetMaxPayloadLength(
-    const uint16_t max_payload_length,
+    const size_t max_payload_length,
     const uint16_t packet_over_head) {
   // Sanity check.
   if (max_payload_length < 100 || max_payload_length > IP_PACKET_SIZE) {
@@ -368,7 +368,7 @@
   return 0;
 }
 
-uint16_t RTPSender::MaxDataPayloadLength() const {
+size_t RTPSender::MaxDataPayloadLength() const {
   int rtx;
   {
     CriticalSectionScoped rtx_lock(send_critsect_);
@@ -383,7 +383,7 @@
   }
 }
 
-uint16_t RTPSender::MaxPayloadLength() const {
+size_t RTPSender::MaxPayloadLength() const {
   return max_payload_length_;
 }
 
@@ -461,7 +461,7 @@
 int32_t RTPSender::SendOutgoingData(
     const FrameType frame_type, const int8_t payload_type,
     const uint32_t capture_timestamp, int64_t capture_time_ms,
-    const uint8_t *payload_data, const uint32_t payload_size,
+    const uint8_t *payload_data, const size_t payload_size,
     const RTPFragmentationHeader *fragmentation,
     VideoCodecInformation *codec_info, const RTPVideoTypeHeader *rtp_type_hdr) {
   uint32_t ssrc;
@@ -513,7 +513,7 @@
   return ret_val;
 }
 
-int RTPSender::TrySendRedundantPayloads(int bytes_to_send) {
+size_t RTPSender::TrySendRedundantPayloads(size_t bytes_to_send) {
   {
     CriticalSectionScoped cs(send_critsect_);
     if ((rtx_ & kRtxRedundantPayloads) == 0)
@@ -521,44 +521,41 @@
   }
 
   uint8_t buffer[IP_PACKET_SIZE];
-  int bytes_left = bytes_to_send;
+  int bytes_left = static_cast<int>(bytes_to_send);
   while (bytes_left > 0) {
-    uint16_t length = bytes_left;
+    size_t length = bytes_left;
     int64_t capture_time_ms;
     if (!packet_history_.GetBestFittingPacket(buffer, &length,
                                               &capture_time_ms)) {
       break;
     }
     if (!PrepareAndSendPacket(buffer, length, capture_time_ms, true, false))
-      return -1;
+      break;
     RtpUtility::RtpHeaderParser rtp_parser(buffer, length);
     RTPHeader rtp_header;
     rtp_parser.Parse(rtp_header);
-    bytes_left -= length - rtp_header.headerLength;
+    bytes_left -= static_cast<int>(length - rtp_header.headerLength);
   }
   return bytes_to_send - bytes_left;
 }
 
-int RTPSender::BuildPaddingPacket(uint8_t* packet, int header_length,
-                                  int32_t bytes) {
-  int padding_bytes_in_packet = kMaxPaddingLength;
-  if (bytes < kMaxPaddingLength) {
-    padding_bytes_in_packet = bytes;
-  }
+size_t RTPSender::BuildPaddingPacket(uint8_t* packet, size_t header_length) {
+  size_t padding_bytes_in_packet = kMaxPaddingLength;
   packet[0] |= 0x20;  // Set padding bit.
   int32_t *data =
       reinterpret_cast<int32_t *>(&(packet[header_length]));
 
   // Fill data buffer with random data.
-  for (int j = 0; j < (padding_bytes_in_packet >> 2); ++j) {
+  for (size_t j = 0; j < (padding_bytes_in_packet >> 2); ++j) {
     data[j] = rand();  // NOLINT
   }
   // Set number of padding bytes in the last byte of the packet.
-  packet[header_length + padding_bytes_in_packet - 1] = padding_bytes_in_packet;
+  packet[header_length + padding_bytes_in_packet - 1] =
+      static_cast<uint8_t>(padding_bytes_in_packet);
   return padding_bytes_in_packet;
 }
 
-int RTPSender::TrySendPadData(int bytes) {
+size_t RTPSender::TrySendPadData(size_t bytes) {
   int64_t capture_time_ms;
   uint32_t timestamp;
   {
@@ -575,11 +572,11 @@
   return SendPadData(timestamp, capture_time_ms, bytes);
 }
 
-int RTPSender::SendPadData(uint32_t timestamp,
-                           int64_t capture_time_ms,
-                           int32_t bytes) {
-  int padding_bytes_in_packet = 0;
-  int bytes_sent = 0;
+size_t RTPSender::SendPadData(uint32_t timestamp,
+                              int64_t capture_time_ms,
+                              size_t bytes) {
+  size_t padding_bytes_in_packet = 0;
+  size_t bytes_sent = 0;
   for (; bytes > 0; bytes -= padding_bytes_in_packet) {
     // Always send full padding packets.
     if (bytes < kMaxPaddingLength)
@@ -618,17 +615,18 @@
     }
 
     uint8_t padding_packet[IP_PACKET_SIZE];
-    int header_length = CreateRTPHeader(padding_packet,
-                                        payload_type,
-                                        ssrc,
-                                        false,
-                                        timestamp,
-                                        sequence_number,
-                                        NULL,
-                                        0);
-    padding_bytes_in_packet =
-        BuildPaddingPacket(padding_packet, header_length, bytes);
-    int length = padding_bytes_in_packet + header_length;
+    size_t header_length = CreateRTPHeader(padding_packet,
+                                           payload_type,
+                                           ssrc,
+                                           false,
+                                           timestamp,
+                                           sequence_number,
+                                           NULL,
+                                           0);
+    assert(header_length != static_cast<size_t>(-1));
+    padding_bytes_in_packet = BuildPaddingPacket(padding_packet, header_length);
+    assert(padding_bytes_in_packet <= bytes);
+    size_t length = padding_bytes_in_packet + header_length;
     int64_t now_ms = clock_->TimeInMilliseconds();
 
     RtpUtility::RtpHeaderParser rtp_parser(padding_packet, length);
@@ -660,7 +658,7 @@
 }
 
 int32_t RTPSender::ReSendPacket(uint16_t packet_id, uint32_t min_resend_time) {
-  uint16_t length = IP_PACKET_SIZE;
+  size_t length = IP_PACKET_SIZE;
   uint8_t data_buffer[IP_PACKET_SIZE];
   int64_t capture_time_ms;
   if (!packet_history_.GetPacketAndSetSendTime(packet_id, min_resend_time, true,
@@ -695,10 +693,10 @@
   }
   return PrepareAndSendPacket(data_buffer, length, capture_time_ms,
                               (rtx & kRtxRetransmitted) > 0, true) ?
-      length : -1;
+      static_cast<int32_t>(length) : -1;
 }
 
-bool RTPSender::SendPacketToNetwork(const uint8_t *packet, uint32_t size) {
+bool RTPSender::SendPacketToNetwork(const uint8_t *packet, size_t size) {
   int bytes_sent = -1;
   if (transport_) {
     bytes_sent = transport_->SendPacket(id_, packet, size);
@@ -731,7 +729,7 @@
   TRACE_EVENT2("webrtc_rtp", "RTPSender::OnReceivedNACK",
                "num_seqnum", nack_sequence_numbers.size(), "avg_rtt", avg_rtt);
   const int64_t now = clock_->TimeInMilliseconds();
-  uint32_t bytes_re_sent = 0;
+  size_t bytes_re_sent = 0;
   uint32_t target_bitrate = GetTargetBitrate();
 
   // Enough bandwidth to send NACK?
@@ -759,8 +757,8 @@
     // Delay bandwidth estimate (RTT * BW).
     if (target_bitrate != 0 && avg_rtt) {
       // kbits/s * ms = bits => bits/8 = bytes
-      uint32_t target_bytes =
-          (static_cast<uint32_t>(target_bitrate / 1000) * avg_rtt) >> 3;
+      size_t target_bytes =
+          (static_cast<size_t>(target_bitrate / 1000) * avg_rtt) >> 3;
       if (bytes_re_sent > target_bytes) {
         break;  // Ignore the rest of the packets in the list.
       }
@@ -775,7 +773,7 @@
 
 bool RTPSender::ProcessNACKBitRate(const uint32_t now) {
   uint32_t num = 0;
-  int byte_count = 0;
+  size_t byte_count = 0;
   const uint32_t kAvgIntervalMs = 1000;
   uint32_t target_bitrate = GetTargetBitrate();
 
@@ -800,11 +798,10 @@
       time_interval = now - nack_byte_count_times_[num - 1];
     }
   }
-  return (byte_count * 8) <
-         static_cast<int>(target_bitrate / 1000 * time_interval);
+  return (byte_count * 8) < (target_bitrate / 1000 * time_interval);
 }
 
-void RTPSender::UpdateNACKBitRate(const uint32_t bytes,
+void RTPSender::UpdateNACKBitRate(const size_t bytes,
                                   const uint32_t now) {
   CriticalSectionScoped cs(send_critsect_);
 
@@ -833,7 +830,7 @@
 bool RTPSender::TimeToSendPacket(uint16_t sequence_number,
                                  int64_t capture_time_ms,
                                  bool retransmission) {
-  uint16_t length = IP_PACKET_SIZE;
+  size_t length = IP_PACKET_SIZE;
   uint8_t data_buffer[IP_PACKET_SIZE];
   int64_t stored_time_ms;
 
@@ -862,7 +859,7 @@
 }
 
 bool RTPSender::PrepareAndSendPacket(uint8_t* buffer,
-                                     uint16_t length,
+                                     size_t length,
                                      int64_t capture_time_ms,
                                      bool send_over_rtx,
                                      bool is_retransmit) {
@@ -901,7 +898,7 @@
 }
 
 void RTPSender::UpdateRtpStats(const uint8_t* buffer,
-                               uint32_t size,
+                               size_t size,
                                const RTPHeader& header,
                                bool is_rtx,
                                bool is_retransmit) {
@@ -949,22 +946,22 @@
       buffer[header.headerLength] == pt_fec;
 }
 
-int RTPSender::TimeToSendPadding(int bytes) {
+size_t RTPSender::TimeToSendPadding(size_t bytes) {
   {
     CriticalSectionScoped cs(send_critsect_);
     if (!sending_media_) return 0;
   }
-  int available_bytes = bytes;
-  if (available_bytes > 0)
-    available_bytes -= TrySendRedundantPayloads(available_bytes);
-  if (available_bytes > 0)
-    available_bytes -= TrySendPadData(available_bytes);
-  return bytes - available_bytes;
+  if (bytes == 0)
+    return 0;
+  size_t bytes_sent = TrySendRedundantPayloads(bytes);
+  if (bytes_sent < bytes)
+    bytes_sent += TrySendPadData(bytes - bytes_sent);
+  return bytes_sent;
 }
 
 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again.
 int32_t RTPSender::SendToNetwork(
-    uint8_t *buffer, int payload_length, int rtp_header_length,
+    uint8_t *buffer, size_t payload_length, size_t rtp_header_length,
     int64_t capture_time_ms, StorageType storage,
     PacedSender::Priority priority) {
   RtpUtility::RtpHeaderParser rtp_parser(buffer,
@@ -1013,7 +1010,7 @@
   if (capture_time_ms > 0) {
     UpdateDelayStatistics(capture_time_ms, now_ms);
   }
-  uint32_t length = payload_length + rtp_header_length;
+  size_t length = payload_length + rtp_header_length;
   if (!SendPacketToNetwork(buffer, length))
     return -1;
   {
@@ -1057,9 +1054,9 @@
   video_->ProcessBitrate();
 }
 
-uint16_t RTPSender::RTPHeaderLength() const {
+size_t RTPSender::RTPHeaderLength() const {
   CriticalSectionScoped lock(send_critsect_);
-  uint16_t rtp_header_length = 12;
+  size_t rtp_header_length = 12;
   if (include_csrcs_) {
     rtp_header_length += sizeof(uint32_t) * num_csrcs_;
   }
@@ -1326,7 +1323,7 @@
 }
 
 void RTPSender::UpdateTransmissionTimeOffset(
-    uint8_t *rtp_packet, const uint16_t rtp_packet_length,
+    uint8_t *rtp_packet, const size_t rtp_packet_length,
     const RTPHeader &rtp_header, const int64_t time_diff_ms) const {
   CriticalSectionScoped cs(send_critsect_);
   // Get id.
@@ -1345,7 +1342,7 @@
         << "Failed to update transmission time offset, not registered.";
     return;
   }
-  int block_pos = 12 + rtp_header.numCSRCs + extension_block_pos;
+  size_t block_pos = 12 + rtp_header.numCSRCs + extension_block_pos;
   if (rtp_packet_length < block_pos + kTransmissionTimeOffsetLength ||
       rtp_header.headerLength <
           block_pos + kTransmissionTimeOffsetLength) {
@@ -1372,7 +1369,7 @@
 }
 
 bool RTPSender::UpdateAudioLevel(uint8_t *rtp_packet,
-                                 const uint16_t rtp_packet_length,
+                                 const size_t rtp_packet_length,
                                  const RTPHeader &rtp_header,
                                  const bool is_voiced,
                                  const uint8_t dBov) const {
@@ -1392,7 +1389,7 @@
     // The feature is not enabled.
     return false;
   }
-  int block_pos = 12 + rtp_header.numCSRCs + extension_block_pos;
+  size_t block_pos = 12 + rtp_header.numCSRCs + extension_block_pos;
   if (rtp_packet_length < block_pos + kAudioLevelLength ||
       rtp_header.headerLength < block_pos + kAudioLevelLength) {
     LOG(LS_WARNING) << "Failed to update audio level, invalid length.";
@@ -1415,7 +1412,7 @@
 }
 
 void RTPSender::UpdateAbsoluteSendTime(
-    uint8_t *rtp_packet, const uint16_t rtp_packet_length,
+    uint8_t *rtp_packet, const size_t rtp_packet_length,
     const RTPHeader &rtp_header, const int64_t now_ms) const {
   CriticalSectionScoped cs(send_critsect_);
 
@@ -1434,7 +1431,7 @@
     // The feature is not enabled.
     return;
   }
-  int block_pos = 12 + rtp_header.numCSRCs + extension_block_pos;
+  size_t block_pos = 12 + rtp_header.numCSRCs + extension_block_pos;
   if (rtp_packet_length < block_pos + kAbsoluteSendTimeLength ||
       rtp_header.headerLength < block_pos + kAbsoluteSendTimeLength) {
     LOG(LS_WARNING) << "Failed to update absolute send time, invalid length.";
@@ -1685,7 +1682,7 @@
   return video_->SetFecParameters(delta_params, key_params);
 }
 
-void RTPSender::BuildRtxPacket(uint8_t* buffer, uint16_t* length,
+void RTPSender::BuildRtxPacket(uint8_t* buffer, size_t* length,
                                uint8_t* buffer_rtx) {
   CriticalSectionScoped cs(send_critsect_);
   uint8_t* data_buffer_rtx = buffer_rtx;
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.h b/webrtc/modules/rtp_rtcp/source/rtp_sender.h
index 6564d47..4781aae 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.h
@@ -52,16 +52,16 @@
                                  const bool timestamp_provided = true,
                                  const bool inc_sequence_number = true) = 0;
 
-  virtual uint16_t RTPHeaderLength() const = 0;
+  virtual size_t RTPHeaderLength() const = 0;
   virtual uint16_t IncrementSequenceNumber() = 0;
   virtual uint16_t SequenceNumber() const = 0;
-  virtual uint16_t MaxPayloadLength() const = 0;
-  virtual uint16_t MaxDataPayloadLength() const = 0;
+  virtual size_t MaxPayloadLength() const = 0;
+  virtual size_t MaxDataPayloadLength() const = 0;
   virtual uint16_t PacketOverHead() const = 0;
   virtual uint16_t ActualSendBitrateKbit() const = 0;
 
   virtual int32_t SendToNetwork(
-      uint8_t *data_buffer, int payload_length, int rtp_header_length,
+      uint8_t *data_buffer, size_t payload_length, size_t rtp_header_length,
       int64_t capture_time_ms, StorageType storage,
       PacedSender::Priority priority) = 0;
 };
@@ -91,8 +91,8 @@
   void SetTargetBitrate(uint32_t bitrate);
   uint32_t GetTargetBitrate();
 
-  virtual uint16_t MaxDataPayloadLength() const
-      OVERRIDE;  // with RTP and FEC headers.
+  // Includes size of RTP and FEC headers.
+  virtual size_t MaxDataPayloadLength() const OVERRIDE;
 
   int32_t RegisterPayload(
       const char payload_name[RTP_PAYLOAD_NAME_SIZE],
@@ -133,7 +133,7 @@
   void SetCSRCs(const uint32_t arr_of_csrc[kRtpCsrcSize],
                 const uint8_t arr_length);
 
-  int32_t SetMaxPayloadLength(const uint16_t length,
+  int32_t SetMaxPayloadLength(const size_t length,
                               const uint16_t packet_over_head);
 
   int32_t SendOutgoingData(const FrameType frame_type,
@@ -141,7 +141,7 @@
                            const uint32_t timestamp,
                            int64_t capture_time_ms,
                            const uint8_t* payload_data,
-                           const uint32_t payload_size,
+                           const size_t payload_size,
                            const RTPFragmentationHeader* fragmentation,
                            VideoCodecInformation* codec_info = NULL,
                            const RTPVideoTypeHeader* rtp_type_hdr = NULL);
@@ -157,7 +157,7 @@
 
   int32_t DeregisterRtpHeaderExtension(const RTPExtensionType type);
 
-  uint16_t RtpHeaderExtensionTotalLength() const;
+  size_t RtpHeaderExtensionTotalLength() const;
 
   uint16_t BuildRTPHeaderExtension(uint8_t* data_buffer) const;
 
@@ -166,14 +166,14 @@
   uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const;
 
   bool UpdateAudioLevel(uint8_t *rtp_packet,
-                        const uint16_t rtp_packet_length,
+                        const size_t rtp_packet_length,
                         const RTPHeader &rtp_header,
                         const bool is_voiced,
                         const uint8_t dBov) const;
 
   bool TimeToSendPacket(uint16_t sequence_number, int64_t capture_time_ms,
                         bool retransmission);
-  int TimeToSendPadding(int bytes);
+  size_t TimeToSendPadding(size_t bytes);
 
   // NACK.
   int SelectiveRetransmissions() const;
@@ -210,9 +210,9 @@
       const bool timestamp_provided = true,
       const bool inc_sequence_number = true) OVERRIDE;
 
-  virtual uint16_t RTPHeaderLength() const OVERRIDE;
+  virtual size_t RTPHeaderLength() const OVERRIDE;
   virtual uint16_t IncrementSequenceNumber() OVERRIDE;
-  virtual uint16_t MaxPayloadLength() const OVERRIDE;
+  virtual size_t MaxPayloadLength() const OVERRIDE;
   virtual uint16_t PacketOverHead() const OVERRIDE;
 
   // Current timestamp.
@@ -220,7 +220,7 @@
   virtual uint32_t SSRC() const OVERRIDE;
 
   virtual int32_t SendToNetwork(
-      uint8_t *data_buffer, int payload_length, int rtp_header_length,
+      uint8_t *data_buffer, size_t payload_length, size_t rtp_header_length,
       int64_t capture_time_ms, StorageType storage,
       PacedSender::Priority priority) OVERRIDE;
 
@@ -267,9 +267,9 @@
   int32_t SetFecParameters(const FecProtectionParams *delta_params,
                            const FecProtectionParams *key_params);
 
-  int SendPadData(uint32_t timestamp,
-                  int64_t capture_time_ms,
-                  int32_t bytes);
+  size_t SendPadData(uint32_t timestamp,
+                     int64_t capture_time_ms,
+                     size_t bytes);
 
   // Called on update of RTP statistics.
   void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback);
@@ -297,38 +297,39 @@
                       uint32_t timestamp, uint16_t sequence_number,
                       const uint32_t* csrcs, uint8_t csrcs_length) const;
 
-  void UpdateNACKBitRate(const uint32_t bytes, const uint32_t now);
+  void UpdateNACKBitRate(const size_t bytes, const uint32_t now);
 
   bool PrepareAndSendPacket(uint8_t* buffer,
-                            uint16_t length,
+                            size_t length,
                             int64_t capture_time_ms,
                             bool send_over_rtx,
                             bool is_retransmit);
 
-  // Return the number of bytes sent.
-  int TrySendRedundantPayloads(int bytes);
-  int TrySendPadData(int bytes);
+  // Return the number of bytes sent.  Note that both of these functions may
+  // return a larger value that their argument.
+  size_t TrySendRedundantPayloads(size_t bytes);
+  size_t TrySendPadData(size_t bytes);
 
-  int BuildPaddingPacket(uint8_t* packet, int header_length, int32_t bytes);
+  size_t BuildPaddingPacket(uint8_t* packet, size_t header_length);
 
-  void BuildRtxPacket(uint8_t* buffer, uint16_t* length,
+  void BuildRtxPacket(uint8_t* buffer, size_t* length,
                       uint8_t* buffer_rtx);
 
-  bool SendPacketToNetwork(const uint8_t *packet, uint32_t size);
+  bool SendPacketToNetwork(const uint8_t *packet, size_t size);
 
   void UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms);
 
   void UpdateTransmissionTimeOffset(uint8_t *rtp_packet,
-                                    const uint16_t rtp_packet_length,
+                                    const size_t rtp_packet_length,
                                     const RTPHeader &rtp_header,
                                     const int64_t time_diff_ms) const;
   void UpdateAbsoluteSendTime(uint8_t *rtp_packet,
-                              const uint16_t rtp_packet_length,
+                              const size_t rtp_packet_length,
                               const RTPHeader &rtp_header,
                               const int64_t now_ms) const;
 
   void UpdateRtpStats(const uint8_t* buffer,
-                      uint32_t size,
+                      size_t size,
                       const RTPHeader& header,
                       bool is_rtx,
                       bool is_retransmit);
@@ -352,7 +353,7 @@
   Transport *transport_;
   bool sending_media_ GUARDED_BY(send_critsect_);
 
-  uint16_t max_payload_length_;
+  size_t max_payload_length_;
   uint16_t packet_over_head_;
 
   int8_t payload_type_ GUARDED_BY(send_critsect_);
@@ -364,7 +365,7 @@
 
   // NACK
   uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE];
-  int32_t nack_byte_count_[NACK_BYTECOUNT_SIZE];
+  size_t nack_byte_count_[NACK_BYTECOUNT_SIZE];
   Bitrate nack_bitrate_;
 
   RTPPacketHistory packet_history_;
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc
index 7efe987..084a39c 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc
@@ -233,11 +233,11 @@
     const int8_t payloadType,
     const uint32_t captureTimeStamp,
     const uint8_t* payloadData,
-    const uint32_t dataSize,
+    const size_t dataSize,
     const RTPFragmentationHeader* fragmentation) {
   // TODO(pwestin) Breakup function in smaller functions.
-  uint16_t payloadSize = static_cast<uint16_t>(dataSize);
-  uint16_t maxPayloadLength = _rtpSender->MaxPayloadLength();
+  size_t payloadSize = dataSize;
+  size_t maxPayloadLength = _rtpSender->MaxPayloadLength();
   bool dtmfToneStarted = false;
   uint16_t dtmfLengthMS = 0;
   uint8_t key = 0;
@@ -383,7 +383,7 @@
         // only 0x80 if we have multiple blocks
         dataBuffer[rtpHeaderLength++] = 0x80 +
             fragmentation->fragmentationPlType[1];
-        uint32_t blockLength = fragmentation->fragmentationLength[1];
+        size_t blockLength = fragmentation->fragmentationLength[1];
 
         // sanity blockLength
         if(blockLength > 0x3ff) {  // block length 10 bits 1023 bytes
@@ -406,9 +406,8 @@
                payloadData + fragmentation->fragmentationOffset[0],
                fragmentation->fragmentationLength[0]);
 
-        payloadSize = static_cast<uint16_t>(
-            fragmentation->fragmentationLength[0] +
-            fragmentation->fragmentationLength[1]);
+        payloadSize = fragmentation->fragmentationLength[0] +
+            fragmentation->fragmentationLength[1];
       } else {
         // silence for too long send only new data
         dataBuffer[rtpHeaderLength++] = fragmentation->fragmentationPlType[0];
@@ -416,8 +415,7 @@
                payloadData + fragmentation->fragmentationOffset[0],
                fragmentation->fragmentationLength[0]);
 
-        payloadSize = static_cast<uint16_t>(
-            fragmentation->fragmentationLength[0]);
+        payloadSize = fragmentation->fragmentationLength[0];
       }
     } else {
       if (fragmentation && fragmentation->fragmentationVectorSize > 0) {
@@ -427,8 +425,7 @@
                 payloadData + fragmentation->fragmentationOffset[0],
                 fragmentation->fragmentationLength[0]);
 
-        payloadSize = static_cast<uint16_t>(
-            fragmentation->fragmentationLength[0]);
+        payloadSize = fragmentation->fragmentationLength[0];
       } else {
         memcpy(dataBuffer+rtpHeaderLength, payloadData, payloadSize);
       }
@@ -437,7 +434,7 @@
 
     // Update audio level extension, if included.
     {
-      uint16_t packetSize = payloadSize + rtpHeaderLength;
+      size_t packetSize = payloadSize + rtpHeaderLength;
       RtpUtility::RtpHeaderParser rtp_parser(dataBuffer, packetSize);
       RTPHeader rtp_header;
       rtp_parser.Parse(rtp_header);
@@ -451,7 +448,7 @@
                          "seqnum", _rtpSender->SequenceNumber());
   return _rtpSender->SendToNetwork(dataBuffer,
                                    payloadSize,
-                                   static_cast<uint16_t>(rtpHeaderLength),
+                                   rtpHeaderLength,
                                    -1,
                                    kAllowRetransmission,
                                    PacedSender::kHighPriority);
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h b/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h
index d3f67e5..1affd2a 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h
@@ -37,7 +37,7 @@
                       const int8_t payloadType,
                       const uint32_t captureTimeStamp,
                       const uint8_t* payloadData,
-                      const uint32_t payloadSize,
+                      const size_t payloadSize,
                       const RTPFragmentationHeader* fragmentation);
 
     // set audio packet size, used to determine when it's time to send a DTMF packet in silence (CNG)
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc
index 2a49477..905b559 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc
@@ -49,11 +49,9 @@
   return packet + rtp_header.headerLength;
 }
 
-uint16_t GetPayloadDataLength(const RTPHeader& rtp_header,
-                              const uint16_t packet_length) {
-  uint16_t length = packet_length - rtp_header.headerLength -
-      rtp_header.paddingLength;
-  return static_cast<uint16_t>(length);
+size_t GetPayloadDataLength(const RTPHeader& rtp_header,
+                            const size_t packet_length) {
+  return packet_length - rtp_header.headerLength - rtp_header.paddingLength;
 }
 
 uint64_t ConvertMsToAbsSendTime(int64_t time_ms) {
@@ -64,18 +62,20 @@
  public:
   LoopbackTransportTest()
       : packets_sent_(0), last_sent_packet_len_(0), total_bytes_sent_(0) {}
-  virtual int SendPacket(int channel, const void *data, int len) OVERRIDE {
+  virtual int SendPacket(int channel, const void *data, size_t len) OVERRIDE {
     packets_sent_++;
     memcpy(last_sent_packet_, data, len);
     last_sent_packet_len_ = len;
-    total_bytes_sent_ += static_cast<size_t>(len);
-    return len;
+    total_bytes_sent_ += len;
+    return static_cast<int>(len);
   }
-  virtual int SendRTCPPacket(int channel, const void *data, int len) OVERRIDE {
+  virtual int SendRTCPPacket(int channel,
+                             const void *data,
+                             size_t len) OVERRIDE {
     return -1;
   }
   int packets_sent_;
-  int last_sent_packet_len_;
+  size_t last_sent_packet_len_;
   size_t total_bytes_sent_;
   uint8_t last_sent_packet_[kMaxPacketLength];
 };
@@ -114,7 +114,7 @@
     EXPECT_EQ(kTimestamp, rtp_header.timestamp);
     EXPECT_EQ(rtp_sender_->SSRC(), rtp_header.ssrc);
     EXPECT_EQ(0, rtp_header.numCSRCs);
-    EXPECT_EQ(0, rtp_header.paddingLength);
+    EXPECT_EQ(0U, rtp_header.paddingLength);
   }
 
   void SendPacket(int64_t capture_time_ms, int payload_length) {
@@ -124,6 +124,7 @@
                                                      kMarkerBit,
                                                      timestamp,
                                                      capture_time_ms);
+    ASSERT_GE(rtp_length, 0);
 
     // Packet should be stored in a send bucket.
     EXPECT_EQ(0, rtp_sender_->SendToNetwork(packet_,
@@ -136,40 +137,40 @@
 };
 
 TEST_F(RtpSenderTest, RegisterRtpTransmissionTimeOffsetHeaderExtension) {
-  EXPECT_EQ(0, rtp_sender_->RtpHeaderExtensionTotalLength());
+  EXPECT_EQ(0u, rtp_sender_->RtpHeaderExtensionTotalLength());
   EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
       kRtpExtensionTransmissionTimeOffset, kTransmissionTimeOffsetExtensionId));
   EXPECT_EQ(kRtpOneByteHeaderLength + kTransmissionTimeOffsetLength,
             rtp_sender_->RtpHeaderExtensionTotalLength());
   EXPECT_EQ(0, rtp_sender_->DeregisterRtpHeaderExtension(
       kRtpExtensionTransmissionTimeOffset));
-  EXPECT_EQ(0, rtp_sender_->RtpHeaderExtensionTotalLength());
+  EXPECT_EQ(0u, rtp_sender_->RtpHeaderExtensionTotalLength());
 }
 
 TEST_F(RtpSenderTest, RegisterRtpAbsoluteSendTimeHeaderExtension) {
-  EXPECT_EQ(0, rtp_sender_->RtpHeaderExtensionTotalLength());
+  EXPECT_EQ(0u, rtp_sender_->RtpHeaderExtensionTotalLength());
   EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
       kRtpExtensionAbsoluteSendTime, kAbsoluteSendTimeExtensionId));
   EXPECT_EQ(kRtpOneByteHeaderLength + kAbsoluteSendTimeLength,
             rtp_sender_->RtpHeaderExtensionTotalLength());
   EXPECT_EQ(0, rtp_sender_->DeregisterRtpHeaderExtension(
       kRtpExtensionAbsoluteSendTime));
-  EXPECT_EQ(0, rtp_sender_->RtpHeaderExtensionTotalLength());
+  EXPECT_EQ(0u, rtp_sender_->RtpHeaderExtensionTotalLength());
 }
 
 TEST_F(RtpSenderTest, RegisterRtpAudioLevelHeaderExtension) {
-  EXPECT_EQ(0, rtp_sender_->RtpHeaderExtensionTotalLength());
+  EXPECT_EQ(0u, rtp_sender_->RtpHeaderExtensionTotalLength());
   EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
       kRtpExtensionAudioLevel, kAudioLevelExtensionId));
   EXPECT_EQ(kRtpOneByteHeaderLength + kAudioLevelLength,
             rtp_sender_->RtpHeaderExtensionTotalLength());
   EXPECT_EQ(0, rtp_sender_->DeregisterRtpHeaderExtension(
       kRtpExtensionAudioLevel));
-  EXPECT_EQ(0, rtp_sender_->RtpHeaderExtensionTotalLength());
+  EXPECT_EQ(0u, rtp_sender_->RtpHeaderExtensionTotalLength());
 }
 
 TEST_F(RtpSenderTest, RegisterRtpHeaderExtensions) {
-  EXPECT_EQ(0, rtp_sender_->RtpHeaderExtensionTotalLength());
+  EXPECT_EQ(0u, rtp_sender_->RtpHeaderExtensionTotalLength());
   EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
       kRtpExtensionTransmissionTimeOffset, kTransmissionTimeOffsetExtensionId));
   EXPECT_EQ(kRtpOneByteHeaderLength + kTransmissionTimeOffsetLength,
@@ -193,16 +194,13 @@
       rtp_sender_->RtpHeaderExtensionTotalLength());
   EXPECT_EQ(0, rtp_sender_->DeregisterRtpHeaderExtension(
       kRtpExtensionAudioLevel));
-  EXPECT_EQ(0, rtp_sender_->RtpHeaderExtensionTotalLength());
+  EXPECT_EQ(0u, rtp_sender_->RtpHeaderExtensionTotalLength());
 }
 
 TEST_F(RtpSenderTest, BuildRTPPacket) {
-  int32_t length = rtp_sender_->BuildRTPheader(packet_,
-                                               kPayload,
-                                               kMarkerBit,
-                                               kTimestamp,
-                                               0);
-  EXPECT_EQ(kRtpHeaderSize, length);
+  size_t length = static_cast<size_t>(rtp_sender_->BuildRTPheader(
+      packet_, kPayload, kMarkerBit, kTimestamp, 0));
+  ASSERT_EQ(kRtpHeaderSize, length);
 
   // Verify
   webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet_, length);
@@ -227,13 +225,10 @@
   EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
       kRtpExtensionTransmissionTimeOffset, kTransmissionTimeOffsetExtensionId));
 
-  int32_t length = rtp_sender_->BuildRTPheader(packet_,
-                                               kPayload,
-                                               kMarkerBit,
-                                               kTimestamp,
-                                               0);
-  EXPECT_EQ(kRtpHeaderSize + rtp_sender_->RtpHeaderExtensionTotalLength(),
-      length);
+  size_t length = static_cast<size_t>(rtp_sender_->BuildRTPheader(
+      packet_, kPayload, kMarkerBit, kTimestamp, 0));
+  ASSERT_EQ(kRtpHeaderSize + rtp_sender_->RtpHeaderExtensionTotalLength(),
+            length);
 
   // Verify
   webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet_, length);
@@ -268,13 +263,10 @@
   EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
       kRtpExtensionTransmissionTimeOffset, kTransmissionTimeOffsetExtensionId));
 
-  int32_t length = rtp_sender_->BuildRTPheader(packet_,
-                                               kPayload,
-                                               kMarkerBit,
-                                               kTimestamp,
-                                               0);
-  EXPECT_EQ(kRtpHeaderSize + rtp_sender_->RtpHeaderExtensionTotalLength(),
-      length);
+  size_t length = static_cast<size_t>(rtp_sender_->BuildRTPheader(
+      packet_, kPayload, kMarkerBit, kTimestamp, 0));
+  ASSERT_EQ(kRtpHeaderSize + rtp_sender_->RtpHeaderExtensionTotalLength(),
+            length);
 
   // Verify
   webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet_, length);
@@ -298,13 +290,10 @@
   EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
       kRtpExtensionAbsoluteSendTime, kAbsoluteSendTimeExtensionId));
 
-  int32_t length = rtp_sender_->BuildRTPheader(packet_,
-                                               kPayload,
-                                               kMarkerBit,
-                                               kTimestamp,
-                                               0);
-  EXPECT_EQ(kRtpHeaderSize + rtp_sender_->RtpHeaderExtensionTotalLength(),
-      length);
+  size_t length = static_cast<size_t>(rtp_sender_->BuildRTPheader(
+      packet_, kPayload, kMarkerBit, kTimestamp, 0));
+  ASSERT_EQ(kRtpHeaderSize + rtp_sender_->RtpHeaderExtensionTotalLength(),
+            length);
 
   // Verify
   webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet_, length);
@@ -336,13 +325,10 @@
   EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
       kRtpExtensionAudioLevel, kAudioLevelExtensionId));
 
-  int32_t length = rtp_sender_->BuildRTPheader(packet_,
-                                               kPayload,
-                                               kMarkerBit,
-                                               kTimestamp,
-                                               0);
-  EXPECT_EQ(kRtpHeaderSize + rtp_sender_->RtpHeaderExtensionTotalLength(),
-      length);
+  size_t length = static_cast<size_t>(rtp_sender_->BuildRTPheader(
+      packet_, kPayload, kMarkerBit, kTimestamp, 0));
+  ASSERT_EQ(kRtpHeaderSize + rtp_sender_->RtpHeaderExtensionTotalLength(),
+            length);
 
   // Verify
   webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet_, length);
@@ -386,13 +372,10 @@
   EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
       kRtpExtensionAudioLevel, kAudioLevelExtensionId));
 
-  int32_t length = rtp_sender_->BuildRTPheader(packet_,
-                                               kPayload,
-                                               kMarkerBit,
-                                               kTimestamp,
-                                               0);
-  EXPECT_EQ(kRtpHeaderSize + rtp_sender_->RtpHeaderExtensionTotalLength(),
-      length);
+  size_t length = static_cast<size_t>(rtp_sender_->BuildRTPheader(
+      packet_, kPayload, kMarkerBit, kTimestamp, 0));
+  ASSERT_EQ(kRtpHeaderSize + rtp_sender_->RtpHeaderExtensionTotalLength(),
+            length);
 
   // Verify
   webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet_, length);
@@ -447,11 +430,10 @@
       kRtpExtensionAbsoluteSendTime, kAbsoluteSendTimeExtensionId));
   rtp_sender_->SetTargetBitrate(300000);
   int64_t capture_time_ms = fake_clock_.TimeInMilliseconds();
-  int32_t rtp_length = rtp_sender_->BuildRTPheader(packet_,
-                                                   kPayload,
-                                                   kMarkerBit,
-                                                   kTimestamp,
-                                                   capture_time_ms);
+  int rtp_length_int = rtp_sender_->BuildRTPheader(
+      packet_, kPayload, kMarkerBit, kTimestamp, capture_time_ms);
+  ASSERT_NE(-1, rtp_length_int);
+  size_t rtp_length = static_cast<size_t>(rtp_length_int);
 
   // Packet should be stored in a send bucket.
   EXPECT_EQ(0, rtp_sender_->SendToNetwork(packet_,
@@ -501,11 +483,10 @@
       kRtpExtensionAbsoluteSendTime, kAbsoluteSendTimeExtensionId));
   rtp_sender_->SetTargetBitrate(300000);
   int64_t capture_time_ms = fake_clock_.TimeInMilliseconds();
-  int32_t rtp_length = rtp_sender_->BuildRTPheader(packet_,
-                                                   kPayload,
-                                                   kMarkerBit,
-                                                   kTimestamp,
-                                                   capture_time_ms);
+  int rtp_length_int = rtp_sender_->BuildRTPheader(
+      packet_, kPayload, kMarkerBit, kTimestamp, capture_time_ms);
+  ASSERT_NE(-1, rtp_length_int);
+  size_t rtp_length = static_cast<size_t>(rtp_length_int);
 
   // Packet should be stored in a send bucket.
   EXPECT_EQ(0, rtp_sender_->SendToNetwork(packet_,
@@ -524,7 +505,7 @@
   const int kStoredTimeInMs = 100;
   fake_clock_.AdvanceTimeMilliseconds(kStoredTimeInMs);
 
-  EXPECT_EQ(rtp_length, rtp_sender_->ReSendPacket(kSeqNum));
+  EXPECT_EQ(rtp_length_int, rtp_sender_->ReSendPacket(kSeqNum));
   EXPECT_EQ(0, transport_.packets_sent_);
 
   rtp_sender_->TimeToSendPacket(kSeqNum, capture_time_ms, false);
@@ -562,7 +543,7 @@
   uint16_t seq_num = kSeqNum;
   uint32_t timestamp = kTimestamp;
   rtp_sender_->SetStorePacketsStatus(true, 10);
-  int32_t rtp_header_len = kRtpHeaderSize;
+  size_t rtp_header_len = kRtpHeaderSize;
   EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
       kRtpExtensionTransmissionTimeOffset, kTransmissionTimeOffsetExtensionId));
   rtp_header_len += 4;  // 4 bytes extension.
@@ -583,11 +564,10 @@
 
   rtp_sender_->SetTargetBitrate(300000);
   int64_t capture_time_ms = fake_clock_.TimeInMilliseconds();
-  int32_t rtp_length = rtp_sender_->BuildRTPheader(packet_,
-                                                   kPayload,
-                                                   kMarkerBit,
-                                                   timestamp,
-                                                   capture_time_ms);
+  int rtp_length_int = rtp_sender_->BuildRTPheader(
+      packet_, kPayload, kMarkerBit, timestamp, capture_time_ms);
+  ASSERT_NE(-1, rtp_length_int);
+  size_t rtp_length = static_cast<size_t>(rtp_length_int);
 
   // Packet should be stored in a send bucket.
   EXPECT_EQ(0, rtp_sender_->SendToNetwork(packet_,
@@ -611,8 +591,8 @@
   // Send padding 4 times, waiting 50 ms between each.
   for (int i = 0; i < 4; ++i) {
     const int kPaddingPeriodMs = 50;
-    const int kPaddingBytes = 100;
-    const int kMaxPaddingLength = 224;  // Value taken from rtp_sender.cc.
+    const size_t kPaddingBytes = 100;
+    const size_t kMaxPaddingLength = 224;  // Value taken from rtp_sender.cc.
     // Padding will be forced to full packets.
     EXPECT_EQ(kMaxPaddingLength, rtp_sender_->TimeToSendPadding(kPaddingBytes));
 
@@ -638,11 +618,10 @@
 
   // Send a regular video packet again.
   capture_time_ms = fake_clock_.TimeInMilliseconds();
-  rtp_length = rtp_sender_->BuildRTPheader(packet_,
-                                           kPayload,
-                                           kMarkerBit,
-                                           timestamp,
-                                           capture_time_ms);
+  rtp_length_int = rtp_sender_->BuildRTPheader(
+      packet_, kPayload, kMarkerBit, timestamp, capture_time_ms);
+  ASSERT_NE(-1, rtp_length_int);
+  rtp_length = static_cast<size_t>(rtp_length_int);
 
   // Packet should be stored in a send bucket.
   EXPECT_EQ(0, rtp_sender_->SendToNetwork(packet_,
@@ -716,15 +695,12 @@
   EXPECT_CALL(transport,
               SendPacket(_, _, kMaxPaddingSize + rtp_header_len))
       .WillOnce(testing::ReturnArg<2>());
-  EXPECT_EQ(kMaxPaddingSize,
-            static_cast<size_t>(rtp_sender_->TimeToSendPadding(49)));
+  EXPECT_EQ(kMaxPaddingSize, rtp_sender_->TimeToSendPadding(49));
 
-  const int kRtxHeaderSize = 2;
   EXPECT_CALL(transport, SendPacket(_, _, kPayloadSizes[0] +
                                     rtp_header_len + kRtxHeaderSize))
       .WillOnce(testing::ReturnArg<2>());
-  EXPECT_EQ(kPayloadSizes[0],
-            static_cast<size_t>(rtp_sender_->TimeToSendPadding(500)));
+  EXPECT_EQ(kPayloadSizes[0], rtp_sender_->TimeToSendPadding(500));
 
   EXPECT_CALL(transport, SendPacket(_, _, kPayloadSizes[kNumPayloadSizes - 1] +
                                     rtp_header_len + kRtxHeaderSize))
@@ -732,7 +708,7 @@
   EXPECT_CALL(transport, SendPacket(_, _, kMaxPaddingSize + rtp_header_len))
       .WillOnce(testing::ReturnArg<2>());
   EXPECT_EQ(kPayloadSizes[kNumPayloadSizes - 1] + kMaxPaddingSize,
-            static_cast<size_t>(rtp_sender_->TimeToSendPadding(999)));
+            rtp_sender_->TimeToSendPadding(999));
 }
 
 TEST_F(RtpSenderTest, SendGenericVideo) {
@@ -951,8 +927,8 @@
 
     uint32_t ssrc_;
     StreamDataCounters counters_;
-    bool Matches(uint32_t ssrc, uint32_t bytes, uint32_t header_bytes,
-                 uint32_t padding, uint32_t packets, uint32_t retransmits,
+    bool Matches(uint32_t ssrc, size_t bytes, size_t header_bytes,
+                 size_t padding, uint32_t packets, uint32_t retransmits,
                  uint32_t fec) {
       return ssrc_ == ssrc &&
           counters_.bytes == bytes &&
@@ -1034,8 +1010,8 @@
   const uint8_t* payload_data = GetPayloadData(rtp_header,
       transport_.last_sent_packet_);
 
-  ASSERT_EQ(sizeof(payload), GetPayloadDataLength(rtp_header,
-            transport_.last_sent_packet_len_));
+  ASSERT_EQ(sizeof(payload),
+            GetPayloadDataLength(rtp_header, transport_.last_sent_packet_len_));
 
   EXPECT_EQ(0, memcmp(payload, payload_data, sizeof(payload)));
 }
@@ -1063,8 +1039,8 @@
   const uint8_t* payload_data = GetPayloadData(rtp_header,
                                                transport_.last_sent_packet_);
 
-  ASSERT_EQ(sizeof(payload), GetPayloadDataLength(
-      rtp_header, transport_.last_sent_packet_len_));
+  ASSERT_EQ(sizeof(payload),
+            GetPayloadDataLength(rtp_header, transport_.last_sent_packet_len_));
 
   EXPECT_EQ(0, memcmp(payload, payload_data, sizeof(payload)));
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc
index ec031df..4792dfa 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc
@@ -100,16 +100,16 @@
 }
 
 int32_t RTPSenderVideo::SendVideoPacket(uint8_t* data_buffer,
-                                        const uint16_t payload_length,
-                                        const uint16_t rtp_header_length,
+                                        const size_t payload_length,
+                                        const size_t rtp_header_length,
                                         const uint32_t capture_timestamp,
                                         int64_t capture_time_ms,
                                         StorageType storage,
                                         bool protect) {
   if (_fecEnabled) {
     int ret = 0;
-    int fec_overhead_sent = 0;
-    int video_sent = 0;
+    size_t fec_overhead_sent = 0;
+    size_t video_sent = 0;
 
     RedPacket* red_packet = producer_fec_.BuildRedPacket(
         data_buffer, payload_length, rtp_header_length, _payloadTypeRED);
@@ -202,7 +202,7 @@
   // RFC 2032
   // 5.2.1.  Full intra-frame Request (FIR) packet
 
-  uint16_t length = 8;
+  size_t length = 8;
   uint8_t data[8];
   data[0] = 0x80;
   data[1] = 192;
@@ -242,7 +242,7 @@
   return 0;
 }
 
-uint16_t RTPSenderVideo::FECPacketOverhead() const {
+size_t RTPSenderVideo::FECPacketOverhead() const {
   if (_fecEnabled) {
     // Overhead is FEC headers plus RED for FEC header plus anything in RTP
     // header beyond the 12 bytes base header (CSRC list, extensions...)
@@ -271,7 +271,7 @@
                                   const uint32_t captureTimeStamp,
                                   int64_t capture_time_ms,
                                   const uint8_t* payloadData,
-                                  const uint32_t payloadSize,
+                                  const size_t payloadSize,
                                   const RTPFragmentationHeader* fragmentation,
                                   VideoCodecInformation* codecInfo,
                                   const RTPVideoTypeHeader* rtpTypeHdr) {
@@ -320,11 +320,11 @@
                           const uint32_t captureTimeStamp,
                           int64_t capture_time_ms,
                           const uint8_t* payloadData,
-                          const uint32_t payloadSize,
+                          const size_t payloadSize,
                           const RTPFragmentationHeader* fragmentation,
                           const RTPVideoTypeHeader* rtpTypeHdr) {
   uint16_t rtp_header_length = _rtpSender.RTPHeaderLength();
-  int32_t payload_bytes_to_send = payloadSize;
+  size_t payload_bytes_to_send = payloadSize;
   const uint8_t* data = payloadData;
   size_t max_payload_length = _rtpSender.MaxDataPayloadLength();
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h
index 250e36b..f043950 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h
@@ -35,7 +35,7 @@
 
   virtual RtpVideoCodecTypes VideoCodecType() const;
 
-  uint16_t FECPacketOverhead() const;
+  size_t FECPacketOverhead() const;
 
   int32_t RegisterVideoPayload(const char payloadName[RTP_PAYLOAD_NAME_SIZE],
                                const int8_t payloadType,
@@ -48,7 +48,7 @@
                     const uint32_t captureTimeStamp,
                     int64_t capture_time_ms,
                     const uint8_t* payloadData,
-                    const uint32_t payloadSize,
+                    const size_t payloadSize,
                     const RTPFragmentationHeader* fragmentation,
                     VideoCodecInformation* codecInfo,
                     const RTPVideoTypeHeader* rtpTypeHdr);
@@ -85,8 +85,8 @@
 
  protected:
   virtual int32_t SendVideoPacket(uint8_t* dataBuffer,
-                                  const uint16_t payloadLength,
-                                  const uint16_t rtpHeaderLength,
+                                  const size_t payloadLength,
+                                  const size_t rtpHeaderLength,
                                   const uint32_t capture_timestamp,
                                   int64_t capture_time_ms,
                                   StorageType storage,
@@ -99,7 +99,7 @@
             const uint32_t captureTimeStamp,
             int64_t capture_time_ms,
             const uint8_t* payloadData,
-            const uint32_t payloadSize,
+            const size_t payloadSize,
             const RTPFragmentationHeader* fragmentation,
             const RTPVideoTypeHeader* rtpTypeHdr);
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_utility.cc b/webrtc/modules/rtp_rtcp/source/rtp_utility.cc
index 441a9c5..2897fac 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_utility.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_utility.cc
@@ -286,7 +286,7 @@
   }
 
   const uint8_t PT = _ptrRTPDataBegin[1];
-  const uint16_t len = (_ptrRTPDataBegin[2] << 8) + _ptrRTPDataBegin[3];
+  const size_t len = (_ptrRTPDataBegin[2] << 8) + _ptrRTPDataBegin[3];
   const uint8_t* ptr = &_ptrRTPDataBegin[4];
 
   uint32_t SSRC = *ptr++ << 24;
@@ -338,7 +338,7 @@
     return false;
   }
 
-  const uint8_t CSRCocts = CC * 4;
+  const size_t CSRCocts = CC * 4;
 
   if ((ptr + CSRCocts) > _ptrRTPDataEnd) {
     return false;
@@ -352,7 +352,7 @@
   header.numCSRCs       = CC;
   header.paddingLength  = P ? *(_ptrRTPDataEnd - 1) : 0;
 
-  for (unsigned int i = 0; i < CC; ++i) {
+  for (uint8_t i = 0; i < CC; ++i) {
     uint32_t CSRC = *ptr++ << 24;
     CSRC += *ptr++ << 16;
     CSRC += *ptr++ << 8;
@@ -395,11 +395,11 @@
     uint16_t definedByProfile = *ptr++ << 8;
     definedByProfile += *ptr++;
 
-    uint16_t XLen = *ptr++ << 8;
+    size_t XLen = *ptr++ << 8;
     XLen += *ptr++; // in 32 bit words
     XLen *= 4; // in octs
 
-    if (remain < (4 + XLen)) {
+    if (static_cast<size_t>(remain) < (4 + XLen)) {
       return false;
     }
     if (definedByProfile == kRtpOneByteHeaderExtensionId) {
diff --git a/webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator.cc b/webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator.cc
index e62df1f..feed784 100644
--- a/webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator.cc
+++ b/webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator.cc
@@ -19,9 +19,9 @@
 namespace webrtc {
 
 PartitionTreeNode::PartitionTreeNode(PartitionTreeNode* parent,
-                                     const int* size_vector,
-                                     int num_partitions,
-                                     int this_size)
+                                     const size_t* size_vector,
+                                     size_t num_partitions,
+                                     size_t this_size)
     : parent_(parent),
       this_size_(this_size),
       size_vector_(size_vector),
@@ -29,13 +29,14 @@
       max_parent_size_(0),
       min_parent_size_(std::numeric_limits<int>::max()),
       packet_start_(false) {
-  assert(num_partitions >= 0);
+  // If |this_size_| > INT_MAX, Cost() and CreateChildren() won't work properly.
+  assert(this_size_ <= static_cast<size_t>(std::numeric_limits<int>::max()));
   children_[kLeftChild] = NULL;
   children_[kRightChild] = NULL;
 }
 
-PartitionTreeNode* PartitionTreeNode::CreateRootNode(const int* size_vector,
-                                                     int num_partitions) {
+PartitionTreeNode* PartitionTreeNode::CreateRootNode(const size_t* size_vector,
+                                                     size_t num_partitions) {
   PartitionTreeNode* root_node =
       new PartitionTreeNode(NULL, &size_vector[1], num_partitions - 1,
                             size_vector[0]);
@@ -48,20 +49,19 @@
   delete children_[kRightChild];
 }
 
-int PartitionTreeNode::Cost(int penalty) {
-  assert(penalty >= 0);
+int PartitionTreeNode::Cost(size_t penalty) {
   int cost = 0;
   if (num_partitions_ == 0) {
     // This is a solution node.
-    cost = std::max(max_parent_size_, this_size_) -
-        std::min(min_parent_size_, this_size_);
+    cost = std::max(max_parent_size_, this_size_int()) -
+        std::min(min_parent_size_, this_size_int());
   } else {
-    cost = std::max(max_parent_size_, this_size_) - min_parent_size_;
+    cost = std::max(max_parent_size_, this_size_int()) - min_parent_size_;
   }
   return cost + NumPackets() * penalty;
 }
 
-bool PartitionTreeNode::CreateChildren(int max_size) {
+bool PartitionTreeNode::CreateChildren(size_t max_size) {
   assert(max_size > 0);
   bool children_created = false;
   if (num_partitions_ > 0) {
@@ -85,9 +85,9 @@
                                                      num_partitions_ - 1,
                                                      size_vector_[0]);
       children_[kRightChild]->set_max_parent_size(
-          std::max(max_parent_size_, this_size_));
+          std::max(max_parent_size_, this_size_int()));
       children_[kRightChild]->set_min_parent_size(
-          std::min(min_parent_size_, this_size_));
+          std::min(min_parent_size_, this_size_int()));
       // "Right" child starts a new packet.
       children_[kRightChild]->set_packet_start(true);
       children_created = true;
@@ -96,7 +96,7 @@
   return children_created;
 }
 
-int PartitionTreeNode::NumPackets() {
+size_t PartitionTreeNode::NumPackets() {
   if (parent_ == NULL) {
     // Root node is a "right" child by definition.
     return 1;
@@ -110,8 +110,8 @@
   }
 }
 
-PartitionTreeNode* PartitionTreeNode::GetOptimalNode(int max_size,
-                                                     int penalty) {
+PartitionTreeNode* PartitionTreeNode::GetOptimalNode(size_t max_size,
+                                                     size_t penalty) {
   CreateChildren(max_size);
   PartitionTreeNode* left = children_[kLeftChild];
   PartitionTreeNode* right = children_[kRightChild];
@@ -148,12 +148,11 @@
 
 Vp8PartitionAggregator::Vp8PartitionAggregator(
     const RTPFragmentationHeader& fragmentation,
-    int first_partition_idx, int last_partition_idx)
+    size_t first_partition_idx, size_t last_partition_idx)
     : root_(NULL),
       num_partitions_(last_partition_idx - first_partition_idx + 1),
-      size_vector_(new int[num_partitions_]),
+      size_vector_(new size_t[num_partitions_]),
       largest_partition_size_(0) {
-  assert(first_partition_idx >= 0);
   assert(last_partition_idx >= first_partition_idx);
   assert(last_partition_idx < fragmentation.fragmentationVectorSize);
   for (size_t i = 0; i < num_partitions_; ++i) {
@@ -179,17 +178,18 @@
 }
 
 Vp8PartitionAggregator::ConfigVec
-Vp8PartitionAggregator::FindOptimalConfiguration(int max_size, int penalty) {
+Vp8PartitionAggregator::FindOptimalConfiguration(size_t max_size,
+                                                 size_t penalty) {
   assert(root_);
   assert(max_size >= largest_partition_size_);
   PartitionTreeNode* opt = root_->GetOptimalNode(max_size, penalty);
   ConfigVec config_vector(num_partitions_, 0);
   PartitionTreeNode* temp_node = opt;
-  int packet_index = opt->NumPackets() - 1;
-  for (int i = num_partitions_ - 1; i >= 0; --i) {
-    assert(packet_index >= 0);
+  size_t packet_index = opt->NumPackets();
+  for (size_t i = num_partitions_; i > 0; --i) {
+    assert(packet_index > 0);
     assert(temp_node != NULL);
-    config_vector[i] = packet_index;
+    config_vector[i - 1] = packet_index - 1;
     if (temp_node->packet_start()) --packet_index;
     temp_node = temp_node->parent();
   }
@@ -204,51 +204,54 @@
   if (*max_size < 0) {
     *max_size = 0;
   }
-  unsigned int i = 0;
+  size_t i = 0;
   while (i < config.size()) {
-    int this_size = 0;
-    unsigned int j = i;
+    size_t this_size = 0;
+    size_t j = i;
     while (j < config.size() && config[i] == config[j]) {
       this_size += size_vector_[j];
       ++j;
     }
     i = j;
-    if (this_size < *min_size) {
+    if (this_size < static_cast<size_t>(*min_size)) {
       *min_size = this_size;
     }
-    if (this_size > *max_size) {
+    if (this_size > static_cast<size_t>(*max_size)) {
       *max_size = this_size;
     }
   }
 }
 
-int Vp8PartitionAggregator::CalcNumberOfFragments(int large_partition_size,
-                                                  int max_payload_size,
-                                                  int penalty,
-                                                  int min_size,
-                                                  int max_size) {
-  assert(max_size <= max_payload_size);
-  assert(min_size <= max_size);
+size_t Vp8PartitionAggregator::CalcNumberOfFragments(
+    size_t large_partition_size,
+    size_t max_payload_size,
+    size_t penalty,
+    int min_size,
+    int max_size) {
+  assert(large_partition_size > 0);
   assert(max_payload_size > 0);
+  assert(min_size != 0);
+  assert(min_size <= max_size);
+  assert(max_size <= static_cast<int>(max_payload_size));
   // Divisions with rounding up.
-  const int min_number_of_fragments =
+  const size_t min_number_of_fragments =
       (large_partition_size + max_payload_size - 1) / max_payload_size;
   if (min_size < 0 || max_size < 0) {
     // No aggregates produced, so we do not have any size boundaries.
     // Simply split in as few partitions as possible.
     return min_number_of_fragments;
   }
-  const int max_number_of_fragments =
+  const size_t max_number_of_fragments =
       (large_partition_size + min_size - 1) / min_size;
   int num_fragments = -1;
-  int best_cost = std::numeric_limits<int>::max();
-  for (int n = min_number_of_fragments; n <= max_number_of_fragments; ++n) {
+  size_t best_cost = std::numeric_limits<size_t>::max();
+  for (size_t n = min_number_of_fragments; n <= max_number_of_fragments; ++n) {
     // Round up so that we use the largest fragment.
-    int fragment_size = (large_partition_size + n - 1) / n;
-    int cost = 0;
-    if (fragment_size < min_size) {
+    size_t fragment_size = (large_partition_size + n - 1) / n;
+    size_t cost = 0;
+    if (fragment_size < static_cast<size_t>(min_size)) {
       cost = min_size - fragment_size + n * penalty;
-    } else if (fragment_size > max_size) {
+    } else if (fragment_size > static_cast<size_t>(max_size)) {
       cost = fragment_size - max_size + n * penalty;
     } else {
       cost = n * penalty;
diff --git a/webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator.h b/webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator.h
index cbb1207..67babcb 100644
--- a/webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator.h
+++ b/webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator.h
@@ -24,13 +24,13 @@
  public:
   // Create a tree node.
   PartitionTreeNode(PartitionTreeNode* parent,
-                    const int* size_vector,
-                    int num_partitions,
-                    int this_size);
+                    const size_t* size_vector,
+                    size_t num_partitions,
+                    size_t this_size);
 
   // Create a root node.
-  static PartitionTreeNode* CreateRootNode(const int* size_vector,
-                                           int num_partitions);
+  static PartitionTreeNode* CreateRootNode(const size_t* size_vector,
+                                           size_t num_partitions);
 
   ~PartitionTreeNode();
 
@@ -38,18 +38,18 @@
   // will be the actual cost associated with that solution. If not, the cost
   // will be the cost accumulated so far along the current branch (which is a
   // lower bound for any solution along the branch).
-  int Cost(int penalty);
+  int Cost(size_t penalty);
 
   // Create the two children for this node.
-  bool CreateChildren(int max_size);
+  bool CreateChildren(size_t max_size);
 
   // Get the number of packets for the configuration that this node represents.
-  int NumPackets();
+  size_t NumPackets();
 
   // Find the optimal solution given a maximum packet size and a per-packet
   // penalty. The method will be recursively called while the solver is
   // probing down the tree of nodes.
-  PartitionTreeNode* GetOptimalNode(int max_size, int penalty);
+  PartitionTreeNode* GetOptimalNode(size_t max_size, size_t penalty);
 
   // Setters and getters.
   void set_max_parent_size(int size) { max_parent_size_ = size; }
@@ -57,7 +57,7 @@
   PartitionTreeNode* parent() const { return parent_; }
   PartitionTreeNode* left_child() const { return children_[kLeftChild]; }
   PartitionTreeNode* right_child() const { return children_[kRightChild]; }
-  int this_size() const { return this_size_; }
+  size_t this_size() const { return this_size_; }
   bool packet_start() const { return packet_start_; }
 
  private:
@@ -66,13 +66,14 @@
     kRightChild = 1
   };
 
+  int this_size_int() const { return static_cast<int>(this_size_); }
   void set_packet_start(bool value) { packet_start_ = value; }
 
   PartitionTreeNode* parent_;
   PartitionTreeNode* children_[2];
-  int this_size_;
-  const int* size_vector_;
-  int num_partitions_;
+  size_t this_size_;
+  const size_t* size_vector_;
+  size_t num_partitions_;
   int max_parent_size_;
   int min_parent_size_;
   bool packet_start_;
@@ -84,13 +85,14 @@
 // the maximum packet size.
 class Vp8PartitionAggregator {
  public:
-  typedef std::vector<int> ConfigVec;
+  typedef std::vector<size_t> ConfigVec;
 
   // Constructor. All partitions in the fragmentation header from index
   // first_partition_idx to last_partition_idx must be smaller than
   // maximum packet size to be used in FindOptimalConfiguration.
   Vp8PartitionAggregator(const RTPFragmentationHeader& fragmentation,
-                         int first_partition_idx, int last_partition_idx);
+                         size_t first_partition_idx,
+                         size_t last_partition_idx);
 
   ~Vp8PartitionAggregator();
 
@@ -103,7 +105,7 @@
   // first_partition_idx + 1), where each element indicates the packet index
   // for that partition. Thus, the output vector starts at 0 and is increasing
   // up to the number of packets - 1.
-  ConfigVec FindOptimalConfiguration(int max_size, int penalty);
+  ConfigVec FindOptimalConfiguration(size_t max_size, size_t penalty);
 
   // Calculate minimum and maximum packet sizes for a given aggregation config.
   // The extreme packet sizes of the given aggregation are compared with the
@@ -116,17 +118,17 @@
   // be larger than max_payload_size. Each fragment comes at an overhead cost
   // of penalty bytes. If the size of the fragments fall outside the range
   // [min_size, max_size], an extra cost is inflicted.
-  static int CalcNumberOfFragments(int large_partition_size,
-                                   int max_payload_size,
-                                   int penalty,
-                                   int min_size,
-                                   int max_size);
+  static size_t CalcNumberOfFragments(size_t large_partition_size,
+                                      size_t max_payload_size,
+                                      size_t penalty,
+                                      int min_size,
+                                      int max_size);
 
  private:
   PartitionTreeNode* root_;
   size_t num_partitions_;
-  int* size_vector_;
-  int largest_partition_size_;
+  size_t* size_vector_;
+  size_t largest_partition_size_;
 
   DISALLOW_COPY_AND_ASSIGN(Vp8PartitionAggregator);
 };
diff --git a/webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator_unittest.cc b/webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator_unittest.cc
index d4ebd77..4650c94 100644
--- a/webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator_unittest.cc
@@ -16,8 +16,8 @@
 namespace webrtc {
 
 TEST(PartitionTreeNode, CreateAndDelete) {
-  const int kVector[] = {1, 2, 3};
-  const int kNumPartitions = sizeof(kVector) / sizeof(kVector[0]);
+  const size_t kVector[] = {1, 2, 3};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kVector);
   PartitionTreeNode* node1 =
       PartitionTreeNode::CreateRootNode(kVector, kNumPartitions);
   PartitionTreeNode* node2 =
@@ -27,17 +27,17 @@
 }
 
 TEST(PartitionTreeNode, CreateChildrenAndDelete) {
-  const int kVector[] = {1, 2, 3};
-  const int kNumPartitions = sizeof(kVector) / sizeof(kVector[0]);
-  const int kMaxSize = 10;
-  const int kPenalty = 5;
+  const size_t kVector[] = {1, 2, 3};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kVector);
+  const size_t kMaxSize = 10;
+  const size_t kPenalty = 5;
   PartitionTreeNode* root =
       PartitionTreeNode::CreateRootNode(kVector, kNumPartitions);
   EXPECT_TRUE(root->CreateChildren(kMaxSize));
   ASSERT_TRUE(NULL != root->left_child());
   ASSERT_TRUE(NULL != root->right_child());
-  EXPECT_EQ(3, root->left_child()->this_size());
-  EXPECT_EQ(2, root->right_child()->this_size());
+  EXPECT_EQ(3u, root->left_child()->this_size());
+  EXPECT_EQ(2u, root->right_child()->this_size());
   EXPECT_EQ(11, root->right_child()->Cost(kPenalty));
   EXPECT_FALSE(root->left_child()->packet_start());
   EXPECT_TRUE(root->right_child()->packet_start());
@@ -45,17 +45,17 @@
 }
 
 TEST(PartitionTreeNode, FindOptimalConfig) {
-  const int kVector[] = {197, 194, 213, 215, 184, 199, 197, 207};
-  const int kNumPartitions = sizeof(kVector) / sizeof(kVector[0]);
-  const int kMaxSize = 1500;
-  const int kPenalty = 1;
+  const size_t kVector[] = {197, 194, 213, 215, 184, 199, 197, 207};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kVector);
+  const size_t kMaxSize = 1500;
+  const size_t kPenalty = 1;
   PartitionTreeNode* root =
       PartitionTreeNode::CreateRootNode(kVector, kNumPartitions);
   root->set_max_parent_size(500);
   root->set_min_parent_size(300);
   PartitionTreeNode* opt = root->GetOptimalNode(kMaxSize, kPenalty);
   ASSERT_TRUE(opt != NULL);
-  EXPECT_EQ(4, opt->NumPackets());
+  EXPECT_EQ(4u, opt->NumPackets());
   // Expect optimal sequence to be {1, 0, 1, 0, 1, 0, 1, 0}, which corresponds
   // to (right)-left-right-left-right-left-right-left, where the root node is
   // implicitly a "right" node by definition.
@@ -76,23 +76,24 @@
 }
 
 TEST(PartitionTreeNode, FindOptimalConfigSinglePartition) {
-  const int kVector[] = {17};
-  const int kNumPartitions = sizeof(kVector) / sizeof(kVector[0]);
-  const int kMaxSize = 1500;
-  const int kPenalty = 1;
+  const size_t kVector[] = {17};
+  const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kVector);
+  const size_t kMaxSize = 1500;
+  const size_t kPenalty = 1;
   PartitionTreeNode* root =
       PartitionTreeNode::CreateRootNode(kVector, kNumPartitions);
   PartitionTreeNode* opt = root->GetOptimalNode(kMaxSize, kPenalty);
   ASSERT_TRUE(opt != NULL);
-  EXPECT_EQ(1, opt->NumPackets());
+  EXPECT_EQ(1u, opt->NumPackets());
   EXPECT_TRUE(opt == root);
   delete root;
 }
 
-static void VerifyConfiguration(const int* expected_config,
-                                size_t expected_config_len,
-                                const std::vector<int>& opt_config,
-                                const RTPFragmentationHeader& fragmentation) {
+static void VerifyConfiguration(
+    const size_t* expected_config,
+    size_t expected_config_len,
+    const Vp8PartitionAggregator::ConfigVec& opt_config,
+    const RTPFragmentationHeader& fragmentation) {
   ASSERT_EQ(expected_config_len, fragmentation.fragmentationVectorSize);
   EXPECT_EQ(expected_config_len, opt_config.size());
   for (size_t i = 0; i < expected_config_len; ++i) {
@@ -101,7 +102,7 @@
 }
 
 static void VerifyMinMax(const Vp8PartitionAggregator& aggregator,
-                         const std::vector<int>& opt_config,
+                         const Vp8PartitionAggregator::ConfigVec& opt_config,
                          int expected_min,
                          int expected_max) {
   int min_size = -1;
@@ -133,13 +134,12 @@
   Vp8PartitionAggregator* aggregator =
       new Vp8PartitionAggregator(fragmentation, 0, 7);
   aggregator->SetPriorMinMax(300, 500);
-  int kMaxSize = 1500;
-  int kPenalty = 1;
-  std::vector<int> opt_config = aggregator->FindOptimalConfiguration(kMaxSize,
-                                                                     kPenalty);
-  const int kExpectedConfig[] = {0, 0, 1, 1, 2, 2, 3, 3};
-  const size_t kExpectedConfigSize =
-      sizeof(kExpectedConfig) / sizeof(kExpectedConfig[0]);
+  size_t kMaxSize = 1500;
+  size_t kPenalty = 1;
+  Vp8PartitionAggregator::ConfigVec opt_config =
+      aggregator->FindOptimalConfiguration(kMaxSize, kPenalty);
+  const size_t kExpectedConfig[] = {0, 0, 1, 1, 2, 2, 3, 3};
+  const size_t kExpectedConfigSize = GTEST_ARRAY_SIZE_(kExpectedConfig);
   VerifyConfiguration(kExpectedConfig, kExpectedConfigSize, opt_config,
                       fragmentation);
   VerifyMinMax(*aggregator, opt_config, 383, 428);
@@ -166,13 +166,12 @@
   fragmentation.fragmentationLength[7] = 200;
   Vp8PartitionAggregator* aggregator =
       new Vp8PartitionAggregator(fragmentation, 0, 7);
-  int kMaxSize = 1500;
-  int kPenalty = 1;
-  std::vector<int> opt_config = aggregator->FindOptimalConfiguration(kMaxSize,
-                                                                     kPenalty);
-  const int kExpectedConfig[] = {0, 0, 0, 0, 1, 1, 1, 1};
-  const size_t kExpectedConfigSize =
-      sizeof(kExpectedConfig) / sizeof(kExpectedConfig[0]);
+  size_t kMaxSize = 1500;
+  size_t kPenalty = 1;
+  Vp8PartitionAggregator::ConfigVec opt_config =
+      aggregator->FindOptimalConfiguration(kMaxSize, kPenalty);
+  const size_t kExpectedConfig[] = {0, 0, 0, 0, 1, 1, 1, 1};
+  const size_t kExpectedConfigSize = GTEST_ARRAY_SIZE_(kExpectedConfig);
   VerifyConfiguration(kExpectedConfig, kExpectedConfigSize, opt_config,
                       fragmentation);
   VerifyMinMax(*aggregator, opt_config, 800, 800);
@@ -185,13 +184,12 @@
   fragmentation.fragmentationLength[0] = 17;
   Vp8PartitionAggregator* aggregator =
       new Vp8PartitionAggregator(fragmentation, 0, 0);
-  int kMaxSize = 1500;
-  int kPenalty = 1;
-  std::vector<int> opt_config = aggregator->FindOptimalConfiguration(kMaxSize,
-                                                                     kPenalty);
-  const int kExpectedConfig[] = {0};
-  const size_t kExpectedConfigSize =
-      sizeof(kExpectedConfig) / sizeof(kExpectedConfig[0]);
+  size_t kMaxSize = 1500;
+  size_t kPenalty = 1;
+  Vp8PartitionAggregator::ConfigVec opt_config =
+      aggregator->FindOptimalConfiguration(kMaxSize, kPenalty);
+  const size_t kExpectedConfig[] = {0};
+  const size_t kExpectedConfigSize = GTEST_ARRAY_SIZE_(kExpectedConfig);
   VerifyConfiguration(kExpectedConfig, kExpectedConfigSize, opt_config,
                       fragmentation);
   VerifyMinMax(*aggregator, opt_config, 17, 17);
@@ -200,13 +198,13 @@
 
 TEST(Vp8PartitionAggregator, TestCalcNumberOfFragments) {
   const int kMTU = 1500;
-  EXPECT_EQ(2,
+  EXPECT_EQ(2u,
             Vp8PartitionAggregator::CalcNumberOfFragments(
                 1600, kMTU, 1, 300, 900));
-  EXPECT_EQ(3,
+  EXPECT_EQ(3u,
             Vp8PartitionAggregator::CalcNumberOfFragments(
                 1600, kMTU, 1, 300, 798));
-  EXPECT_EQ(2,
+  EXPECT_EQ(2u,
             Vp8PartitionAggregator::CalcNumberOfFragments(
                 1600, kMTU, 1, 900, 1000));
 }
diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/BWEStandAlone.cc b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/BWEStandAlone.cc
index 9e706e7..77ee6fb 100644
--- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/BWEStandAlone.cc
+++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/BWEStandAlone.cc
@@ -33,12 +33,12 @@
 protected:
     // Inherited from UdpTransportData
     virtual void IncomingRTPPacket(const int8_t* incomingRtpPacket,
-                                   const int32_t rtpPacketLength,
+                                   const size_t rtpPacketLength,
                                    const int8_t* fromIP,
                                    const uint16_t fromPort) OVERRIDE;
 
     virtual void IncomingRTCPPacket(const int8_t* incomingRtcpPacket,
-                                    const int32_t rtcpPacketLength,
+                                    const size_t rtcpPacketLength,
                                     const int8_t* fromIP,
                                     const uint16_t fromPort) OVERRIDE;
 
@@ -47,21 +47,21 @@
 };
 
 void myTransportCB::IncomingRTPPacket(const int8_t* incomingRtpPacket,
-                                      const int32_t rtpPacketLength,
+                                      const size_t rtpPacketLength,
                                       const int8_t* fromIP,
                                       const uint16_t fromPort)
 {
     printf("Receiving RTP from IP %s, port %u\n", fromIP, fromPort);
-    _rtpMod->IncomingPacket((uint8_t *) incomingRtpPacket, static_cast<uint16_t>(rtpPacketLength));
+    _rtpMod->IncomingPacket((uint8_t *) incomingRtpPacket, rtpPacketLength);
 }
 
 void myTransportCB::IncomingRTCPPacket(const int8_t* incomingRtcpPacket,
-                                       const int32_t rtcpPacketLength,
+                                       const size_t rtcpPacketLength,
                                        const int8_t* fromIP,
                                        const uint16_t fromPort)
 {
     printf("Receiving RTCP from IP %s, port %u\n", fromIP, fromPort);
-    _rtpMod->IncomingPacket((uint8_t *) incomingRtcpPacket, static_cast<uint16_t>(rtcpPacketLength));
+    _rtpMod->IncomingPacket((uint8_t *) incomingRtcpPacket, rtcpPacketLength);
 }
 
 
diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc
index 6a66f26..6b322f7 100644
--- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc
+++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc
@@ -131,7 +131,7 @@
 
 int TestLoadGenerator::sendPayload (const uint32_t timeStamp,
                                     const uint8_t* payloadData,
-                                    const uint32_t payloadSize,
+                                    const size_t payloadSize,
                                     const webrtc::FrameType frameType /*= webrtc::kVideoFrameDelta*/)
 {
 
@@ -139,7 +139,10 @@
 }
 
 
-CBRGenerator::CBRGenerator (TestSenderReceiver *sender, int32_t payloadSizeBytes, int32_t bitrateKbps, int32_t rtpSampleRate)
+CBRGenerator::CBRGenerator (TestSenderReceiver *sender,
+                            size_t payloadSizeBytes,
+                            int32_t bitrateKbps,
+                            int32_t rtpSampleRate)
 :
 //_eventPtr(NULL),
 _payloadSizeBytes(payloadSizeBytes),
@@ -300,10 +303,10 @@
     return true;
 }
 
-int32_t CBRFixFRGenerator::nextPayloadSize()
+size_t CBRFixFRGenerator::nextPayloadSize()
 {
     const double periodMs = 1000.0 / _frameRateFps;
-    return static_cast<int32_t>(_bitrateKbps * periodMs / 8 + 0.5);
+    return static_cast<size_t>(_bitrateKbps * periodMs / 8 + 0.5);
 }
 
 int CBRFixFRGenerator::generatePayload ( uint32_t timestamp )
@@ -313,7 +316,7 @@
     double factor = ((double) rand() - RAND_MAX/2) / RAND_MAX; // [-0.5; 0.5]
     factor = 1 + 2 * _spreadFactor * factor; // [1 - _spreadFactor ; 1 + _spreadFactor]
 
-    int32_t thisPayloadBytes = static_cast<int32_t>(_payloadSizeBytes * factor);
+    size_t thisPayloadBytes = static_cast<size_t>(_payloadSizeBytes * factor);
     // sanity
     if (thisPayloadBytes > _payloadAllocLen)
     {
@@ -338,15 +341,17 @@
 {
 }
 
-int32_t PeriodicKeyFixFRGenerator::nextPayloadSize()
+size_t PeriodicKeyFixFRGenerator::nextPayloadSize()
 {
     // calculate payload size for a delta frame
-    int32_t payloadSizeBytes = static_cast<int32_t>(1000 * _bitrateKbps / (8.0 * _frameRateFps * (1.0 + (_keyFactor - 1.0) / _keyPeriod)) + 0.5);
+    size_t payloadSizeBytes = static_cast<size_t>(1000 * _bitrateKbps /
+        (8.0 * _frameRateFps * (1.0 + (_keyFactor - 1.0) / _keyPeriod)) + 0.5);
 
     if (_frameCount % _keyPeriod == 0)
     {
         // this is a key frame, scale the payload size
-        payloadSizeBytes = static_cast<int32_t>(_keyFactor * _payloadSizeBytes + 0.5);
+        payloadSizeBytes =
+            static_cast<size_t>(_keyFactor * _payloadSizeBytes + 0.5);
     }
     _frameCount++;
 
@@ -396,7 +401,7 @@
     printf("New frame rate: %d\n", _frameRateFps);
 }
 
-int32_t CBRVarFRGenerator::nextPayloadSize()
+size_t CBRVarFRGenerator::nextPayloadSize()
 {
     ChangeFrameRate();
     return CBRFixFRGenerator::nextPayloadSize();
@@ -416,7 +421,7 @@
 {
 }
 
-int32_t CBRFrameDropGenerator::nextPayloadSize()
+size_t CBRFrameDropGenerator::nextPayloadSize()
 {
     _accBits -= 1000 * _bitrateKbps / _frameRateFps;
     if (_accBits < 0)
@@ -432,8 +437,10 @@
     {
         //printf("keep\n");
         const double periodMs = 1000.0 / _frameRateFps;
-        int32_t frameSize = static_cast<int32_t>(_bitrateKbps * periodMs / 8 + 0.5);
-        frameSize = std::max(frameSize, static_cast<int32_t>(300 * periodMs / 8 + 0.5));
+        size_t frameSize =
+            static_cast<size_t>(_bitrateKbps * periodMs / 8 + 0.5);
+        frameSize =
+            std::max(frameSize, static_cast<size_t>(300 * periodMs / 8 + 0.5));
         _accBits += frameSize * 8;
         return frameSize;
     }
diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h
index 61ebec8..fafdbf0 100644
--- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h
+++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h
@@ -39,7 +39,7 @@
     int generatePayload ();
     int sendPayload (const uint32_t timeStamp,
         const uint8_t* payloadData,
-        const uint32_t payloadSize,
+        const size_t payloadSize,
         const webrtc::FrameType frameType = webrtc::kVideoFrameDelta);
 
     webrtc::CriticalSectionWrapper* _critSect;
@@ -55,7 +55,10 @@
 class CBRGenerator : public TestLoadGenerator
 {
 public:
-    CBRGenerator (TestSenderReceiver *sender, int32_t payloadSizeBytes, int32_t bitrateKbps, int32_t rtpSampleRate = 90000);
+    CBRGenerator (TestSenderReceiver *sender,
+                  size_t payloadSizeBytes,
+                  int32_t bitrateKbps,
+                  int32_t rtpSampleRate = 90000);
     virtual ~CBRGenerator ();
 
     virtual int32_t Start () {return (TestLoadGenerator::Start("CBRGenerator"));};
@@ -65,7 +68,7 @@
 protected:
     virtual int generatePayload ( uint32_t timestamp );
 
-    int32_t _payloadSizeBytes;
+    size_t _payloadSizeBytes;
     uint8_t *_payload;
 };
 
@@ -82,12 +85,12 @@
     virtual bool GeneratorLoop ();
 
 protected:
-    virtual int32_t nextPayloadSize ();
+    virtual size_t nextPayloadSize ();
     virtual int generatePayload ( uint32_t timestamp );
 
-    int32_t _payloadSizeBytes;
+    size_t _payloadSizeBytes;
     uint8_t *_payload;
-    int32_t _payloadAllocLen;
+    size_t _payloadAllocLen;
     int32_t _frameRateFps;
     double      _spreadFactor;
 };
@@ -100,7 +103,7 @@
     virtual ~PeriodicKeyFixFRGenerator () {}
 
 protected:
-    virtual int32_t nextPayloadSize ();
+    virtual size_t nextPayloadSize ();
 
     double          _keyFactor;
     uint32_t    _keyPeriod;
@@ -120,7 +123,7 @@
 
 protected:
     virtual void ChangeFrameRate();
-    virtual int32_t nextPayloadSize ();
+    virtual size_t nextPayloadSize ();
 
     double       _avgFrPeriodMs;
     double       _frSpreadFactor;
@@ -138,7 +141,7 @@
     ~CBRFrameDropGenerator();
 
 protected:
-    virtual int32_t nextPayloadSize();
+    virtual size_t nextPayloadSize();
 
     double       _accBits;
 };
diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc
index a536ebc..50c1981 100644
--- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc
+++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc
@@ -256,9 +256,9 @@
 
 int32_t TestSenderReceiver::ReceiveBitrateKbps ()
 {
-    uint32_t bytesSent;
+    size_t bytesSent;
     uint32_t packetsSent;
-    uint32_t bytesReceived;
+    size_t bytesReceived;
     uint32_t packetsReceived;
 
     if (_rtp->DataCountersRTP(&bytesSent, &packetsSent, &bytesReceived, &packetsReceived) == 0)
@@ -290,7 +290,7 @@
 
 
 int32_t TestSenderReceiver::OnReceivedPayloadData(const uint8_t* payloadData,
-                                                  const uint16_t payloadSize,
+                                                  const size_t payloadSize,
                                                   const webrtc::WebRtcRTPHeader* rtpHeader)
 {
     //printf("OnReceivedPayloadData\n");
@@ -299,21 +299,21 @@
 
 
 void TestSenderReceiver::IncomingRTPPacket(const int8_t* incomingRtpPacket,
-                                      const int32_t rtpPacketLength,
-                                      const int8_t* fromIP,
-                                      const uint16_t fromPort)
+                                           const size_t rtpPacketLength,
+                                           const int8_t* fromIP,
+                                           const uint16_t fromPort)
 {
-    _rtp->IncomingPacket((uint8_t *) incomingRtpPacket, static_cast<uint16_t>(rtpPacketLength));
+    _rtp->IncomingPacket((uint8_t *) incomingRtpPacket, rtpPacketLength);
 }
 
 
 
 void TestSenderReceiver::IncomingRTCPPacket(const int8_t* incomingRtcpPacket,
-                                       const int32_t rtcpPacketLength,
-                                       const int8_t* fromIP,
-                                       const uint16_t fromPort)
+                                            const size_t rtcpPacketLength,
+                                            const int8_t* fromIP,
+                                            const uint16_t fromPort)
 {
-    _rtp->IncomingPacket((uint8_t *) incomingRtcpPacket, static_cast<uint16_t>(rtcpPacketLength));
+    _rtp->IncomingPacket((uint8_t *) incomingRtcpPacket, rtcpPacketLength);
 }
 
 
@@ -386,7 +386,7 @@
 int32_t
 TestSenderReceiver::SendOutgoingData(const uint32_t timeStamp,
                                      const uint8_t* payloadData,
-                                     const uint32_t payloadSize,
+                                     const size_t payloadSize,
                                      const webrtc::FrameType frameType /*= webrtc::kVideoFrameDelta*/)
 {
     return (_rtp->SendOutgoingData(frameType, _payloadType, timeStamp, payloadData, payloadSize));
diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h
index 3968e65..30a84c9 100644
--- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h
+++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h
@@ -90,18 +90,18 @@
     // Inherited from RtpData
     virtual int32_t OnReceivedPayloadData(
         const uint8_t* payloadData,
-        const uint16_t payloadSize,
+        const size_t payloadSize,
         const webrtc::WebRtcRTPHeader* rtpHeader) OVERRIDE;
 
 
     // Inherited from UdpTransportData
     virtual void IncomingRTPPacket(const int8_t* incomingRtpPacket,
-                                   const int32_t rtpPacketLength,
+                                   const size_t rtpPacketLength,
                                    const int8_t* fromIP,
                                    const uint16_t fromPort) OVERRIDE;
 
     virtual void IncomingRTCPPacket(const int8_t* incomingRtcpPacket,
-                                    const int32_t rtcpPacketLength,
+                                    const size_t rtcpPacketLength,
                                     const int8_t* fromIP,
                                     const uint16_t fromPort) OVERRIDE;
 
@@ -118,7 +118,7 @@
 
     int32_t SendOutgoingData(const uint32_t timeStamp,
         const uint8_t* payloadData,
-        const uint32_t payloadSize,
+        const size_t payloadSize,
         const webrtc::FrameType frameType = webrtc::kVideoFrameDelta);
 
     int32_t SetLoadGenerator(TestLoadGenerator *generator);
@@ -150,7 +150,7 @@
     bool _isSender;
     bool _isReceiver;
     SendRecCB * _sendRecCB;
-    uint32_t _lastBytesReceived;
+    size_t _lastBytesReceived;
     int64_t _lastTime;
 
 };
diff --git a/webrtc/modules/rtp_rtcp/test/testAPI/test_api.h b/webrtc/modules/rtp_rtcp/test/testAPI/test_api.h
index bd9d197..0085641 100644
--- a/webrtc/modules/rtp_rtcp/test/testAPI/test_api.h
+++ b/webrtc/modules/rtp_rtcp/test/testAPI/test_api.h
@@ -43,7 +43,7 @@
   void DropEveryNthPacket(int n) {
     _packetLoss = n;
   }
-  virtual int SendPacket(int channel, const void *data, int len) OVERRIDE {
+  virtual int SendPacket(int channel, const void *data, size_t len) OVERRIDE {
     _count++;
     if (_packetLoss > 0) {
       if ((_count % _packetLoss) == 0) {
@@ -52,9 +52,7 @@
     }
     RTPHeader header;
     scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
-    if (!parser->Parse(static_cast<const uint8_t*>(data),
-                       static_cast<size_t>(len),
-                       &header)) {
+    if (!parser->Parse(static_cast<const uint8_t*>(data), len, &header)) {
       return -1;
     }
     PayloadUnion payload_specific;
@@ -70,11 +68,13 @@
     }
     return len;
   }
-  virtual int SendRTCPPacket(int channel, const void *data, int len) OVERRIDE {
+  virtual int SendRTCPPacket(int channel,
+                             const void *data,
+                             size_t len) OVERRIDE {
     if (_rtpRtcpModule->IncomingRtcpPacket((const uint8_t*)data, len) < 0) {
       return -1;
     }
-    return len;
+    return static_cast<int>(len);
   }
  private:
   int _count;
@@ -90,7 +90,7 @@
 
   virtual int32_t OnReceivedPayloadData(
       const uint8_t* payloadData,
-      const uint16_t payloadSize,
+      const size_t payloadSize,
       const webrtc::WebRtcRTPHeader* rtpHeader) OVERRIDE {
     EXPECT_LE(payloadSize, sizeof(_payloadData));
     memcpy(_payloadData, payloadData, payloadSize);
@@ -103,7 +103,7 @@
     return _payloadData;
   }
 
-  uint16_t payload_size() const {
+  size_t payload_size() const {
     return _payloadSize;
   }
 
@@ -113,7 +113,7 @@
 
  private:
   uint8_t _payloadData[1500];
-  uint16_t _payloadSize;
+  size_t _payloadSize;
   webrtc::WebRtcRTPHeader _rtpHeader;
 };
 
diff --git a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc
index 0832f63..49ee83a 100644
--- a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc
+++ b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc
@@ -27,11 +27,11 @@
  public:
   virtual int32_t OnReceivedPayloadData(
       const uint8_t* payloadData,
-      const uint16_t payloadSize,
+      const size_t payloadSize,
       const webrtc::WebRtcRTPHeader* rtpHeader) OVERRIDE {
     if (rtpHeader->header.payloadType == 98 ||
         rtpHeader->header.payloadType == 99) {
-      EXPECT_EQ(4, payloadSize);
+      EXPECT_EQ(4u, payloadSize);
       char str[5];
       memcpy(str, payloadData, payloadSize);
       str[4] = 0;
@@ -265,10 +265,10 @@
 
   RTPFragmentationHeader fragmentation;
   fragmentation.fragmentationVectorSize = 2;
-  fragmentation.fragmentationLength = new uint32_t[2];
+  fragmentation.fragmentationLength = new size_t[2];
   fragmentation.fragmentationLength[0] = 4;
   fragmentation.fragmentationLength[1] = 4;
-  fragmentation.fragmentationOffset = new uint32_t[2];
+  fragmentation.fragmentationOffset = new size_t[2];
   fragmentation.fragmentationOffset[0] = 0;
   fragmentation.fragmentationOffset[1] = 4;
   fragmentation.fragmentationTimeDiff = new uint16_t[2];
diff --git a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_video.cc b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_video.cc
index 4c4944d..ddcfa96 100644
--- a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_video.cc
+++ b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_video.cc
@@ -73,43 +73,42 @@
 
     payload_data_length_ = sizeof(video_frame_);
 
-    for (int n = 0; n < payload_data_length_; n++) {
+    for (size_t n = 0; n < payload_data_length_; n++) {
       video_frame_[n] = n%10;
     }
   }
 
-  int32_t BuildRTPheader(uint8_t* dataBuffer,
-                               uint32_t timestamp,
-                               uint32_t sequence_number) {
+  size_t BuildRTPheader(uint8_t* dataBuffer,
+                         uint32_t timestamp,
+                         uint32_t sequence_number) {
     dataBuffer[0] = static_cast<uint8_t>(0x80);  // version 2
     dataBuffer[1] = static_cast<uint8_t>(kPayloadType);
     RtpUtility::AssignUWord16ToBuffer(dataBuffer + 2, sequence_number);
     RtpUtility::AssignUWord32ToBuffer(dataBuffer + 4, timestamp);
     RtpUtility::AssignUWord32ToBuffer(dataBuffer + 8, 0x1234);  // SSRC.
-    int32_t rtpHeaderLength = 12;
+    size_t rtpHeaderLength = 12;
     return rtpHeaderLength;
   }
 
-  int PaddingPacket(uint8_t* buffer,
-                    uint32_t timestamp,
-                    uint32_t sequence_number,
-                    int32_t bytes) {
+  size_t PaddingPacket(uint8_t* buffer,
+                       uint32_t timestamp,
+                       uint32_t sequence_number,
+                       size_t bytes) {
     // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP.
-    int max_length = 224;
+    size_t max_length = 224;
 
-    int padding_bytes_in_packet = max_length;
+    size_t padding_bytes_in_packet = max_length;
     if (bytes < max_length) {
       padding_bytes_in_packet = (bytes + 16) & 0xffe0;  // Keep our modulus 32.
     }
     // Correct seq num, timestamp and payload type.
-    int header_length = BuildRTPheader(buffer, timestamp,
-                                       sequence_number);
+    size_t header_length = BuildRTPheader(buffer, timestamp, sequence_number);
     buffer[0] |= 0x20;  // Set padding bit.
     int32_t* data =
         reinterpret_cast<int32_t*>(&(buffer[header_length]));
 
     // Fill data buffer with random data.
-    for (int j = 0; j < (padding_bytes_in_packet >> 2); j++) {
+    for (size_t j = 0; j < (padding_bytes_in_packet >> 2); j++) {
       data[j] = rand();  // NOLINT
     }
     // Set number of padding bytes in the last byte of the packet.
@@ -135,7 +134,7 @@
   uint32_t test_timestamp_;
   uint16_t test_sequence_number_;
   uint8_t  video_frame_[65000];
-  int payload_data_length_;
+  size_t payload_data_length_;
   SimulatedClock fake_clock;
   enum { kPayloadType = 100 };
 };
@@ -150,7 +149,7 @@
 }
 
 TEST_F(RtpRtcpVideoTest, PaddingOnlyFrames) {
-  const int kPadSize = 255;
+  const size_t kPadSize = 255;
   uint8_t padding_packet[kPadSize];
   uint32_t seq_num = 0;
   uint32_t timestamp = 3000;
@@ -165,8 +164,8 @@
                                                      codec.maxBitrate));
   for (int frame_idx = 0; frame_idx < 10; ++frame_idx) {
     for (int packet_idx = 0; packet_idx < 5; ++packet_idx) {
-      int packet_size = PaddingPacket(padding_packet, timestamp, seq_num,
-                                      kPadSize);
+      size_t packet_size = PaddingPacket(padding_packet, timestamp, seq_num,
+                                         kPadSize);
       ++seq_num;
       RTPHeader header;
       scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
@@ -175,11 +174,11 @@
       EXPECT_TRUE(rtp_payload_registry_.GetPayloadSpecifics(header.payloadType,
                                                            &payload_specific));
       const uint8_t* payload = padding_packet + header.headerLength;
-      const int payload_length = packet_size - header.headerLength;
+      const size_t payload_length = packet_size - header.headerLength;
       EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, payload,
                                                    payload_length,
                                                    payload_specific, true));
-      EXPECT_EQ(0, receiver_->payload_size());
+      EXPECT_EQ(0u, receiver_->payload_size());
       EXPECT_EQ(payload_length, receiver_->rtp_header().header.paddingLength);
     }
     timestamp += 3000;
diff --git a/webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc b/webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc
index bdb53af..f1353b8 100644
--- a/webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc
+++ b/webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc
@@ -232,7 +232,7 @@
             for (uint32_t i = 0; i < numMediaPackets; ++i) {
               mediaPacket = new ForwardErrorCorrection::Packet;
               mediaPacketList.push_back(mediaPacket);
-              mediaPacket->length = static_cast<uint16_t>(
+              mediaPacket->length = static_cast<size_t>(
                   (static_cast<float>(rand()) / RAND_MAX) *
                   (IP_PACKET_SIZE - 12 - 28 -
                    ForwardErrorCorrection::PacketOverhead()));
@@ -264,7 +264,7 @@
                                                 timeStamp);
               RtpUtility::AssignUWord32ToBuffer(&mediaPacket->data[8], ssrc);
               // Generate random values for payload
-              for (int32_t j = 12; j < mediaPacket->length; ++j) {
+              for (size_t j = 12; j < mediaPacket->length; ++j) {
                 mediaPacket->data[j] = static_cast<uint8_t>(rand() % 256);
               }
               seqNum++;