Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/byte_io.h

Issue 1175263002: Add packetization and coding/decoding of feedback message format. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Updated parsing to match new spec Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 namespace webrtc { 43 namespace webrtc {
44 44
45 // Class for reading integers from a sequence of bytes. 45 // Class for reading integers from a sequence of bytes.
46 // T = type of integer, B = bytes to read, is_signed = true if signed integer 46 // T = type of integer, B = bytes to read, is_signed = true if signed integer
47 // If is_signed is true and B < sizeof(T), sign extension might be needed 47 // If is_signed is true and B < sizeof(T), sign extension might be needed
48 template<typename T, unsigned int B = sizeof(T), 48 template<typename T, unsigned int B = sizeof(T),
49 bool is_signed = std::numeric_limits<T>::is_signed> 49 bool is_signed = std::numeric_limits<T>::is_signed>
50 class ByteReader { 50 class ByteReader {
51 public: 51 public:
52 static T ReadBigEndian(const uint8_t* data) { 52 static T ReadBigEndian(const uint8_t* data) {
53 static_assert(B <= sizeof(T), "Target size too large");
53 if (is_signed && B < sizeof(T)) { 54 if (is_signed && B < sizeof(T)) {
54 return SignExtend(InternalReadBigEndian(data)); 55 return SignExtend(InternalReadBigEndian(data));
55 } 56 }
56 return InternalReadBigEndian(data); 57 return InternalReadBigEndian(data);
57 } 58 }
58 59
59 static T ReadLittleEndian(const uint8_t* data) { 60 static T ReadLittleEndian(const uint8_t* data) {
61 static_assert(B <= sizeof(T), "Target size too large");
60 if (is_signed && B < sizeof(T)) { 62 if (is_signed && B < sizeof(T)) {
61 return SignExtend(InternalReadLittleEndian(data)); 63 return SignExtend(InternalReadLittleEndian(data));
62 } 64 }
63 return InternalReadLittleEndian(data); 65 return InternalReadLittleEndian(data);
64 } 66 }
65 67
66 private: 68 private:
67 static T InternalReadBigEndian(const uint8_t* data) { 69 static T InternalReadBigEndian(const uint8_t* data) {
68 T val(0); 70 T val(0);
69 for (unsigned int i = 0; i < B; ++i) { 71 for (unsigned int i = 0; i < B; ++i) {
(...skipping 29 matching lines...) Expand all
99 return val; 101 return val;
100 } 102 }
101 }; 103 };
102 104
103 // Class for writing integers to a sequence of bytes 105 // Class for writing integers to a sequence of bytes
104 // T = type of integer, B = bytes to write 106 // T = type of integer, B = bytes to write
105 template<typename T, unsigned int B = sizeof(T)> 107 template<typename T, unsigned int B = sizeof(T)>
106 class ByteWriter { 108 class ByteWriter {
107 public: 109 public:
108 static void WriteBigEndian(uint8_t* data, T val) { 110 static void WriteBigEndian(uint8_t* data, T val) {
111 static_assert(B <= sizeof(T), "Target size too large");
109 for (unsigned int i = 0; i < B; ++i) { 112 for (unsigned int i = 0; i < B; ++i) {
110 data[i] = val >> ((B - 1 - i) * 8); 113 data[i] = val >> ((B - 1 - i) * 8);
111 } 114 }
112 } 115 }
113 116
114 static void WriteLittleEndian(uint8_t* data, T val) { 117 static void WriteLittleEndian(uint8_t* data, T val) {
118 static_assert(B <= sizeof(T), "Target size too large");
115 for (unsigned int i = 0; i < B; ++i) { 119 for (unsigned int i = 0; i < B; ++i) {
116 data[i] = val >> (i * 8); 120 data[i] = val >> (i * 8);
117 } 121 }
118 } 122 }
119 }; 123 };
120 124
121 125
122 // -------- Below follows specializations for B in { 2, 4, 8 } -------- 126 // -------- Below follows specializations for B in { 2, 4, 8 } --------
123 127
124 128
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 data[4] = val >> 32; 233 data[4] = val >> 32;
230 data[5] = val >> 40; 234 data[5] = val >> 40;
231 data[6] = val >> 48; 235 data[6] = val >> 48;
232 data[7] = val >> 56; 236 data[7] = val >> 56;
233 } 237 }
234 }; 238 };
235 239
236 } // namespace webrtc 240 } // namespace webrtc
237 241
238 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_BYTE_IO_H_ 242 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_BYTE_IO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698