Make sure ByteReader<T>::Read* is properly constified.

Also, start using it in real code...

BUG=
R=holmer@google.com, pbos@webrtc.org, stefan@webrtc.org

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

Cr-Commit-Position: refs/heads/master@{#8181}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8181 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/rtp_rtcp/source/byte_io.h b/webrtc/modules/rtp_rtcp/source/byte_io.h
index 646f1eb..2617806 100644
--- a/webrtc/modules/rtp_rtcp/source/byte_io.h
+++ b/webrtc/modules/rtp_rtcp/source/byte_io.h
@@ -49,14 +49,14 @@
     bool is_signed = std::numeric_limits<T>::is_signed>
 class ByteReader {
  public:
-  static T ReadBigEndian(uint8_t* data) {
+  static T ReadBigEndian(const uint8_t* data) {
     if (is_signed && B < sizeof(T)) {
       return SignExtend(InternalReadBigEndian(data));
     }
     return InternalReadBigEndian(data);
   }
 
-  static T ReadLittleEndian(uint8_t* data) {
+  static T ReadLittleEndian(const uint8_t* data) {
     if (is_signed && B < sizeof(T)) {
       return SignExtend(InternalReadLittleEndian(data));
     }
@@ -64,7 +64,7 @@
   }
 
  private:
-  static T InternalReadBigEndian(uint8_t* data) {
+  static T InternalReadBigEndian(const uint8_t* data) {
     T val(0);
     for (unsigned int i = 0; i < B; ++i) {
       val |= static_cast<T>(data[i]) << ((B - 1 - i) * 8);
@@ -72,7 +72,7 @@
     return val;
   }
 
-  static T InternalReadLittleEndian(uint8_t* data) {
+  static T InternalReadLittleEndian(const uint8_t* data) {
     T val(0);
     for (unsigned int i = 0; i < B; ++i) {
       val |= static_cast<T>(data[i]) << (i * 8);
@@ -85,7 +85,7 @@
   // extend the remaining byte(s) with ones so that the correct negative
   // number is retained.
   // Ex: 0x810A0B -> 0xFF810A0B, but 0x710A0B -> 0x00710A0B
-  static T SignExtend(T val) {
+  static T SignExtend(const T val) {
     uint8_t msb = static_cast<uint8_t>(val >> ((B - 1) * 8));
     if (msb & 0x80) {
       // Sign extension is -1 (all ones) shifted left B bytes.
@@ -126,11 +126,11 @@
 template<typename T, bool is_signed>
 class ByteReader<T, 2, is_signed> {
  public:
-  static T ReadBigEndian(uint8_t* data) {
+  static T ReadBigEndian(const uint8_t* data) {
     return (data[0] << 8) | data[1];
   }
 
-  static T ReadLittleEndian(uint8_t* data) {
+  static T ReadLittleEndian(const uint8_t* data) {
     return data[0] | (data[1] << 8);
   }
 };
@@ -153,11 +153,11 @@
 template<typename T, bool is_signed>
 class ByteReader<T, 4, is_signed> {
  public:
-  static T ReadBigEndian(uint8_t* data) {
+  static T ReadBigEndian(const uint8_t* data) {
     return (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
   }
 
-  static T ReadLittleEndian(uint8_t* data) {
+  static T ReadLittleEndian(const uint8_t* data) {
     return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
   }
 };
@@ -185,7 +185,7 @@
 template<typename T, bool is_signed>
 class ByteReader<T, 8, is_signed> {
  public:
-  static T ReadBigEndian(uint8_t* data) {
+  static T ReadBigEndian(const uint8_t* data) {
     return
         (Get(data, 0) << 56) | (Get(data, 1) << 48) |
         (Get(data, 2) << 40) | (Get(data, 3) << 32) |
@@ -193,7 +193,7 @@
         (Get(data, 6) << 8)  |  Get(data, 7);
   }
 
-  static T ReadLittleEndian(uint8_t* data) {
+  static T ReadLittleEndian(const uint8_t* data) {
     return
          Get(data, 0)        | (Get(data, 1) << 8)  |
         (Get(data, 2) << 16) | (Get(data, 3) << 24) |
@@ -202,7 +202,7 @@
   }
 
  private:
-  inline static T Get(uint8_t* data, unsigned int index) {
+  inline static T Get(const uint8_t* data, unsigned int index) {
     return static_cast<T>(data[index]);
   }
 };
diff --git a/webrtc/modules/rtp_rtcp/source/byte_io_unittest.cc b/webrtc/modules/rtp_rtcp/source/byte_io_unittest.cc
index 5b70109..8b62618 100644
--- a/webrtc/modules/rtp_rtcp/source/byte_io_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/byte_io_unittest.cc
@@ -52,7 +52,7 @@
 
   // Test reading big endian numbers.
   // Template arguments: Type T, read method RM(buffer), B bytes of data.
-  template <typename T, T (*RM)(uint8_t*), int B>
+  template <typename T, T (*RM)(const uint8_t*), int B>
   void TestRead(bool big_endian) {
     // Test both for values that are positive and negative (if signed)
     for (int neg = 0; neg < 2; ++neg) {
diff --git a/webrtc/video/call.cc b/webrtc/video/call.cc
index 0ed412d..b80d5c0 100644
--- a/webrtc/video/call.cc
+++ b/webrtc/video/call.cc
@@ -19,6 +19,7 @@
 #include "webrtc/common.h"
 #include "webrtc/config.h"
 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
+#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
@@ -439,8 +440,7 @@
   if (length < 12)
     return DELIVERY_PACKET_ERROR;
 
-  const uint8_t* ptr = &packet[8];
-  uint32_t ssrc = ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3];
+  uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]);
 
   ReadLockScoped read_lock(*receive_crit_);
   std::map<uint32_t, VideoReceiveStream*>::iterator it =