diff --git a/webrtc/modules/rtp_rtcp/source/byte_io.h b/webrtc/modules/rtp_rtcp/source/byte_io.h index 646f1eb55d..2617806dd9 100644 --- a/webrtc/modules/rtp_rtcp/source/byte_io.h +++ b/webrtc/modules/rtp_rtcp/source/byte_io.h @@ -49,14 +49,14 @@ template::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 @@ class ByteReader { } 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(data[i]) << ((B - 1 - i) * 8); @@ -72,7 +72,7 @@ class ByteReader { 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(data[i]) << (i * 8); @@ -85,7 +85,7 @@ class ByteReader { // 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(val >> ((B - 1) * 8)); if (msb & 0x80) { // Sign extension is -1 (all ones) shifted left B bytes. @@ -126,11 +126,11 @@ class ByteWriter { template class ByteReader { 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 @@ class ByteWriter { template class ByteReader { 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 @@ class ByteWriter { template class ByteReader { 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 @@ class ByteReader { (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 @@ class ByteReader { } 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(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 5b7010994e..8b626189a0 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 @@ class ByteIoTest : public ::testing::Test { // Test reading big endian numbers. // Template arguments: Type T, read method RM(buffer), B bytes of data. - template + template 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 0ed412d5a8..b80d5c038e 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 @@ PacketReceiver::DeliveryStatus Call::DeliverRtp(const uint8_t* packet, 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::ReadBigEndian(&packet[8]); ReadLockScoped read_lock(*receive_crit_); std::map::iterator it =