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

Side by Side Diff: webrtc/api/sctputils.cc

Issue 1821083002: Split ByteBuffer into writer/reader objects. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | webrtc/base/bitbuffer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 uint8_t message_type = payload[0]; 42 uint8_t message_type = payload[0];
43 return message_type == DATA_CHANNEL_OPEN_MESSAGE_TYPE; 43 return message_type == DATA_CHANNEL_OPEN_MESSAGE_TYPE;
44 } 44 }
45 45
46 bool ParseDataChannelOpenMessage(const rtc::CopyOnWriteBuffer& payload, 46 bool ParseDataChannelOpenMessage(const rtc::CopyOnWriteBuffer& payload,
47 std::string* label, 47 std::string* label,
48 DataChannelInit* config) { 48 DataChannelInit* config) {
49 // Format defined at 49 // Format defined at
50 // http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04 50 // http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04
51 51
52 // TODO(jbauch): avoid copying the payload data into the ByteBuffer, see 52 rtc::ByteBufferReader buffer(payload.data<char>(), payload.size());
53 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5670
54 rtc::ByteBuffer buffer(payload.data<char>(), payload.size());
55 uint8_t message_type; 53 uint8_t message_type;
56 if (!buffer.ReadUInt8(&message_type)) { 54 if (!buffer.ReadUInt8(&message_type)) {
57 LOG(LS_WARNING) << "Could not read OPEN message type."; 55 LOG(LS_WARNING) << "Could not read OPEN message type.";
58 return false; 56 return false;
59 } 57 }
60 if (message_type != DATA_CHANNEL_OPEN_MESSAGE_TYPE) { 58 if (message_type != DATA_CHANNEL_OPEN_MESSAGE_TYPE) {
61 LOG(LS_WARNING) << "Data Channel OPEN message of unexpected type: " 59 LOG(LS_WARNING) << "Data Channel OPEN message of unexpected type: "
62 << message_type; 60 << message_type;
63 return false; 61 return false;
64 } 62 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 channel_type = DCOMCT_UNORDERED_PARTIAL_RTXS; 157 channel_type = DCOMCT_UNORDERED_PARTIAL_RTXS;
160 reliability_param = config.maxRetransmits; 158 reliability_param = config.maxRetransmits;
161 } else if (config.maxRetransmitTime > -1) { 159 } else if (config.maxRetransmitTime > -1) {
162 channel_type = DCOMCT_UNORDERED_PARTIAL_TIME; 160 channel_type = DCOMCT_UNORDERED_PARTIAL_TIME;
163 reliability_param = config.maxRetransmitTime; 161 reliability_param = config.maxRetransmitTime;
164 } else { 162 } else {
165 channel_type = DCOMCT_UNORDERED_RELIABLE; 163 channel_type = DCOMCT_UNORDERED_RELIABLE;
166 } 164 }
167 } 165 }
168 166
169 rtc::ByteBuffer buffer( 167 rtc::ByteBufferWriter buffer(
170 NULL, 20 + label.length() + config.protocol.length(), 168 NULL, 20 + label.length() + config.protocol.length(),
171 rtc::ByteBuffer::ORDER_NETWORK); 169 rtc::ByteBuffer::ORDER_NETWORK);
172 // TODO(tommi): Add error handling and check resulting length. 170 // TODO(tommi): Add error handling and check resulting length.
173 buffer.WriteUInt8(DATA_CHANNEL_OPEN_MESSAGE_TYPE); 171 buffer.WriteUInt8(DATA_CHANNEL_OPEN_MESSAGE_TYPE);
174 buffer.WriteUInt8(channel_type); 172 buffer.WriteUInt8(channel_type);
175 buffer.WriteUInt16(priority); 173 buffer.WriteUInt16(priority);
176 buffer.WriteUInt32(reliability_param); 174 buffer.WriteUInt32(reliability_param);
177 buffer.WriteUInt16(static_cast<uint16_t>(label.length())); 175 buffer.WriteUInt16(static_cast<uint16_t>(label.length()));
178 buffer.WriteUInt16(static_cast<uint16_t>(config.protocol.length())); 176 buffer.WriteUInt16(static_cast<uint16_t>(config.protocol.length()));
179 buffer.WriteString(label); 177 buffer.WriteString(label);
180 buffer.WriteString(config.protocol); 178 buffer.WriteString(config.protocol);
181 payload->SetData(buffer.Data(), buffer.Length()); 179 payload->SetData(buffer.Data(), buffer.Length());
182 return true; 180 return true;
183 } 181 }
184 182
185 void WriteDataChannelOpenAckMessage(rtc::CopyOnWriteBuffer* payload) { 183 void WriteDataChannelOpenAckMessage(rtc::CopyOnWriteBuffer* payload) {
186 uint8_t data = DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE; 184 uint8_t data = DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE;
187 payload->SetData(&data, sizeof(data)); 185 payload->SetData(&data, sizeof(data));
188 } 186 }
189 187
190 } // namespace webrtc 188 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/bitbuffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698