Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 #include "webrtc/api/sctputils.h" | 11 #include "webrtc/api/sctputils.h" |
| 12 | 12 |
| 13 #include "webrtc/base/buffer.h" | |
| 14 #include "webrtc/base/bytebuffer.h" | 13 #include "webrtc/base/bytebuffer.h" |
| 14 #include "webrtc/base/copyonwritebuffer.h" | |
| 15 #include "webrtc/base/logging.h" | 15 #include "webrtc/base/logging.h" |
| 16 | 16 |
| 17 namespace webrtc { | 17 namespace webrtc { |
| 18 | 18 |
| 19 // Format defined at | 19 // Format defined at |
| 20 // http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-01#section | 20 // http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-01#section |
| 21 | 21 |
| 22 static const uint8_t DATA_CHANNEL_OPEN_MESSAGE_TYPE = 0x03; | 22 static const uint8_t DATA_CHANNEL_OPEN_MESSAGE_TYPE = 0x03; |
| 23 static const uint8_t DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE = 0x02; | 23 static const uint8_t DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE = 0x02; |
| 24 | 24 |
| 25 enum DataChannelOpenMessageChannelType { | 25 enum DataChannelOpenMessageChannelType { |
| 26 DCOMCT_ORDERED_RELIABLE = 0x00, | 26 DCOMCT_ORDERED_RELIABLE = 0x00, |
| 27 DCOMCT_ORDERED_PARTIAL_RTXS = 0x01, | 27 DCOMCT_ORDERED_PARTIAL_RTXS = 0x01, |
| 28 DCOMCT_ORDERED_PARTIAL_TIME = 0x02, | 28 DCOMCT_ORDERED_PARTIAL_TIME = 0x02, |
| 29 DCOMCT_UNORDERED_RELIABLE = 0x80, | 29 DCOMCT_UNORDERED_RELIABLE = 0x80, |
| 30 DCOMCT_UNORDERED_PARTIAL_RTXS = 0x81, | 30 DCOMCT_UNORDERED_PARTIAL_RTXS = 0x81, |
| 31 DCOMCT_UNORDERED_PARTIAL_TIME = 0x82, | 31 DCOMCT_UNORDERED_PARTIAL_TIME = 0x82, |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 bool IsOpenMessage(const rtc::Buffer& payload) { | 34 bool IsOpenMessage(const rtc::CopyOnWriteBuffer& payload) { |
| 35 // Format defined at | 35 // Format defined at |
| 36 // http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04 | 36 // http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04 |
| 37 | 37 |
| 38 rtc::ByteBuffer buffer(payload); | 38 // TODO(jbauch): avoid copying the payload data into the ByteBuffer |
| 39 rtc::ByteBuffer buffer(payload.data<char>(), payload.size()); | |
|
tommi
2016/03/18 10:54:37
is this really just to check a single uint8? Can
joachim
2016/03/18 12:18:08
Done, added bracket operators to CopyOnWriteBuffer
| |
| 39 uint8_t message_type; | 40 uint8_t message_type; |
| 40 if (!buffer.ReadUInt8(&message_type)) { | 41 if (!buffer.ReadUInt8(&message_type)) { |
| 41 LOG(LS_WARNING) << "Could not read OPEN message type."; | 42 LOG(LS_WARNING) << "Could not read OPEN message type."; |
| 42 return false; | 43 return false; |
| 43 } | 44 } |
| 44 return message_type == DATA_CHANNEL_OPEN_MESSAGE_TYPE; | 45 return message_type == DATA_CHANNEL_OPEN_MESSAGE_TYPE; |
| 45 } | 46 } |
| 46 | 47 |
| 47 bool ParseDataChannelOpenMessage(const rtc::Buffer& payload, | 48 bool ParseDataChannelOpenMessage(const rtc::CopyOnWriteBuffer& payload, |
| 48 std::string* label, | 49 std::string* label, |
| 49 DataChannelInit* config) { | 50 DataChannelInit* config) { |
| 50 // Format defined at | 51 // Format defined at |
| 51 // http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04 | 52 // http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04 |
| 52 | 53 |
| 53 rtc::ByteBuffer buffer(payload); | 54 // TODO(jbauch): avoid copying the payload data into the ByteBuffer |
| 55 rtc::ByteBuffer buffer(payload.data<char>(), payload.size()); | |
|
tommi
2016/03/18 10:54:37
This is a more complex case of course, maybe file
joachim
2016/03/18 12:18:08
Added https://bugs.chromium.org/p/webrtc/issues/de
| |
| 54 uint8_t message_type; | 56 uint8_t message_type; |
| 55 if (!buffer.ReadUInt8(&message_type)) { | 57 if (!buffer.ReadUInt8(&message_type)) { |
| 56 LOG(LS_WARNING) << "Could not read OPEN message type."; | 58 LOG(LS_WARNING) << "Could not read OPEN message type."; |
| 57 return false; | 59 return false; |
| 58 } | 60 } |
| 59 if (message_type != DATA_CHANNEL_OPEN_MESSAGE_TYPE) { | 61 if (message_type != DATA_CHANNEL_OPEN_MESSAGE_TYPE) { |
| 60 LOG(LS_WARNING) << "Data Channel OPEN message of unexpected type: " | 62 LOG(LS_WARNING) << "Data Channel OPEN message of unexpected type: " |
| 61 << message_type; | 63 << message_type; |
| 62 return false; | 64 return false; |
| 63 } | 65 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 config->maxRetransmits = reliability_param; | 115 config->maxRetransmits = reliability_param; |
| 114 break; | 116 break; |
| 115 case DCOMCT_ORDERED_PARTIAL_TIME: | 117 case DCOMCT_ORDERED_PARTIAL_TIME: |
| 116 case DCOMCT_UNORDERED_PARTIAL_TIME: | 118 case DCOMCT_UNORDERED_PARTIAL_TIME: |
| 117 config->maxRetransmitTime = reliability_param; | 119 config->maxRetransmitTime = reliability_param; |
| 118 break; | 120 break; |
| 119 } | 121 } |
| 120 return true; | 122 return true; |
| 121 } | 123 } |
| 122 | 124 |
| 123 bool ParseDataChannelOpenAckMessage(const rtc::Buffer& payload) { | 125 bool ParseDataChannelOpenAckMessage(const rtc::CopyOnWriteBuffer& payload) { |
| 124 rtc::ByteBuffer buffer(payload); | 126 // TODO(jbauch): avoid copying the payload data into the ByteBuffer |
| 127 rtc::ByteBuffer buffer(payload.data<char>(), payload.size()); | |
|
tommi
2016/03/18 10:54:37
so much copy :(
if we can fix this case now (sinc
joachim
2016/03/18 12:18:08
Done.
| |
| 125 uint8_t message_type; | 128 uint8_t message_type; |
| 126 if (!buffer.ReadUInt8(&message_type)) { | 129 if (!buffer.ReadUInt8(&message_type)) { |
| 127 LOG(LS_WARNING) << "Could not read OPEN_ACK message type."; | 130 LOG(LS_WARNING) << "Could not read OPEN_ACK message type."; |
| 128 return false; | 131 return false; |
| 129 } | 132 } |
| 130 if (message_type != DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE) { | 133 if (message_type != DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE) { |
| 131 LOG(LS_WARNING) << "Data Channel OPEN_ACK message of unexpected type: " | 134 LOG(LS_WARNING) << "Data Channel OPEN_ACK message of unexpected type: " |
| 132 << message_type; | 135 << message_type; |
| 133 return false; | 136 return false; |
| 134 } | 137 } |
| 135 return true; | 138 return true; |
| 136 } | 139 } |
| 137 | 140 |
| 138 bool WriteDataChannelOpenMessage(const std::string& label, | 141 bool WriteDataChannelOpenMessage(const std::string& label, |
| 139 const DataChannelInit& config, | 142 const DataChannelInit& config, |
| 140 rtc::Buffer* payload) { | 143 rtc::CopyOnWriteBuffer* payload) { |
| 141 // Format defined at | 144 // Format defined at |
| 142 // http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-00#section-6.1 | 145 // http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-00#section-6.1 |
| 143 uint8_t channel_type = 0; | 146 uint8_t channel_type = 0; |
| 144 uint32_t reliability_param = 0; | 147 uint32_t reliability_param = 0; |
| 145 uint16_t priority = 0; | 148 uint16_t priority = 0; |
| 146 if (config.ordered) { | 149 if (config.ordered) { |
| 147 if (config.maxRetransmits > -1) { | 150 if (config.maxRetransmits > -1) { |
| 148 channel_type = DCOMCT_ORDERED_PARTIAL_RTXS; | 151 channel_type = DCOMCT_ORDERED_PARTIAL_RTXS; |
| 149 reliability_param = config.maxRetransmits; | 152 reliability_param = config.maxRetransmits; |
| 150 } else if (config.maxRetransmitTime > -1) { | 153 } else if (config.maxRetransmitTime > -1) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 169 NULL, 20 + label.length() + config.protocol.length(), | 172 NULL, 20 + label.length() + config.protocol.length(), |
| 170 rtc::ByteBuffer::ORDER_NETWORK); | 173 rtc::ByteBuffer::ORDER_NETWORK); |
| 171 buffer.WriteUInt8(DATA_CHANNEL_OPEN_MESSAGE_TYPE); | 174 buffer.WriteUInt8(DATA_CHANNEL_OPEN_MESSAGE_TYPE); |
| 172 buffer.WriteUInt8(channel_type); | 175 buffer.WriteUInt8(channel_type); |
| 173 buffer.WriteUInt16(priority); | 176 buffer.WriteUInt16(priority); |
| 174 buffer.WriteUInt32(reliability_param); | 177 buffer.WriteUInt32(reliability_param); |
| 175 buffer.WriteUInt16(static_cast<uint16_t>(label.length())); | 178 buffer.WriteUInt16(static_cast<uint16_t>(label.length())); |
| 176 buffer.WriteUInt16(static_cast<uint16_t>(config.protocol.length())); | 179 buffer.WriteUInt16(static_cast<uint16_t>(config.protocol.length())); |
| 177 buffer.WriteString(label); | 180 buffer.WriteString(label); |
| 178 buffer.WriteString(config.protocol); | 181 buffer.WriteString(config.protocol); |
| 179 payload->SetData(buffer.Data(), buffer.Length()); | 182 payload->SetData(buffer.Data(), buffer.Length()); |
|
tommi
2016/03/18 10:54:37
Hmm... there's no error checking for any of the pr
joachim
2016/03/18 12:18:08
Done.
| |
| 180 return true; | 183 return true; |
| 181 } | 184 } |
| 182 | 185 |
| 183 void WriteDataChannelOpenAckMessage(rtc::Buffer* payload) { | 186 void WriteDataChannelOpenAckMessage(rtc::CopyOnWriteBuffer* payload) { |
| 184 rtc::ByteBuffer buffer(rtc::ByteBuffer::ORDER_NETWORK); | 187 rtc::ByteBuffer buffer(rtc::ByteBuffer::ORDER_NETWORK); |
|
tommi
2016/03/18 10:54:37
I'm curious - do you know what's going on here?
a
joachim
2016/03/18 12:18:08
Yeah, that looks overly complicated - changed to y
| |
| 185 buffer.WriteUInt8(DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE); | 188 buffer.WriteUInt8(DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE); |
| 186 payload->SetData(buffer.Data(), buffer.Length()); | 189 payload->SetData(buffer.Data(), buffer.Length()); |
| 187 } | 190 } |
| 188 } // namespace webrtc | 191 } // namespace webrtc |
| OLD | NEW |