Files
platform-external-webrtc/webrtc/api/sctputils.cc
kjellander 194e3bcc53 Revert of Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies. (patchset #4 id:60001 of https://codereview.webrtc.org/1785713005/ )
Reason for revert:
I'm really sorry for having to revert this but it seems this hit an unexpected compile error downstream:

webrtc/media/sctp/sctpdataengine.cc: In function 'void cricket::VerboseLogPacket(const void*, size_t, int)':
webrtc/media/sctp/sctpdataengine.cc:172:37: error: invalid conversion from 'const void*' to 'void*' [-fpermissive]
              data, length, direction)) != NULL) {
                                     ^
In file included from webrtc/media/sctp/sctpdataengine.cc:20:0:
third_party/usrsctp/usrsctplib/usrsctp.h:964:1: error:   initializing argument 1 of 'char* usrsctp_dumppacket(void*, size_t, int)' [-fpermissive]
 usrsctp_dumppacket(void *, size_t, int);
 ^

I'm sure you can fix this easily and just re-land this CL, while I'm going to look into how to add this warning at the public bots (on Monday).

Original issue's description:
> Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies.
>
> This CL removes copy and assign support from Buffer and changes various
> parameters from Buffer to CopyOnWriteBuffer so they can be passed along
> and copied without actually copying the underlying data.
>
> With this changed some parameters to be "const" and fixed an issue when
> creating a CopyOnWriteBuffer with empty data.
>
> BUG=webrtc:5155
>
> Committed: https://crrev.com/944c39006f1c52aee20919676002dac7a42b1c05
> Cr-Commit-Position: refs/heads/master@{#12058}

TBR=kwiberg@webrtc.org,tkchin@webrtc.org,tommi@webrtc.org,pthatcher@webrtc.org,jbauch@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:5155

Review URL: https://codereview.webrtc.org/1817753003

Cr-Commit-Position: refs/heads/master@{#12060}
2016-03-19 19:12:58 +00:00

189 lines
6.0 KiB
C++

/*
* Copyright 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/api/sctputils.h"
#include "webrtc/base/buffer.h"
#include "webrtc/base/bytebuffer.h"
#include "webrtc/base/logging.h"
namespace webrtc {
// Format defined at
// http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-01#section
static const uint8_t DATA_CHANNEL_OPEN_MESSAGE_TYPE = 0x03;
static const uint8_t DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE = 0x02;
enum DataChannelOpenMessageChannelType {
DCOMCT_ORDERED_RELIABLE = 0x00,
DCOMCT_ORDERED_PARTIAL_RTXS = 0x01,
DCOMCT_ORDERED_PARTIAL_TIME = 0x02,
DCOMCT_UNORDERED_RELIABLE = 0x80,
DCOMCT_UNORDERED_PARTIAL_RTXS = 0x81,
DCOMCT_UNORDERED_PARTIAL_TIME = 0x82,
};
bool IsOpenMessage(const rtc::Buffer& payload) {
// Format defined at
// http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04
rtc::ByteBuffer buffer(payload);
uint8_t message_type;
if (!buffer.ReadUInt8(&message_type)) {
LOG(LS_WARNING) << "Could not read OPEN message type.";
return false;
}
return message_type == DATA_CHANNEL_OPEN_MESSAGE_TYPE;
}
bool ParseDataChannelOpenMessage(const rtc::Buffer& payload,
std::string* label,
DataChannelInit* config) {
// Format defined at
// http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04
rtc::ByteBuffer buffer(payload);
uint8_t message_type;
if (!buffer.ReadUInt8(&message_type)) {
LOG(LS_WARNING) << "Could not read OPEN message type.";
return false;
}
if (message_type != DATA_CHANNEL_OPEN_MESSAGE_TYPE) {
LOG(LS_WARNING) << "Data Channel OPEN message of unexpected type: "
<< message_type;
return false;
}
uint8_t channel_type;
if (!buffer.ReadUInt8(&channel_type)) {
LOG(LS_WARNING) << "Could not read OPEN message channel type.";
return false;
}
uint16_t priority;
if (!buffer.ReadUInt16(&priority)) {
LOG(LS_WARNING) << "Could not read OPEN message reliabilility prioirty.";
return false;
}
uint32_t reliability_param;
if (!buffer.ReadUInt32(&reliability_param)) {
LOG(LS_WARNING) << "Could not read OPEN message reliabilility param.";
return false;
}
uint16_t label_length;
if (!buffer.ReadUInt16(&label_length)) {
LOG(LS_WARNING) << "Could not read OPEN message label length.";
return false;
}
uint16_t protocol_length;
if (!buffer.ReadUInt16(&protocol_length)) {
LOG(LS_WARNING) << "Could not read OPEN message protocol length.";
return false;
}
if (!buffer.ReadString(label, (size_t) label_length)) {
LOG(LS_WARNING) << "Could not read OPEN message label";
return false;
}
if (!buffer.ReadString(&config->protocol, protocol_length)) {
LOG(LS_WARNING) << "Could not read OPEN message protocol.";
return false;
}
config->ordered = true;
switch (channel_type) {
case DCOMCT_UNORDERED_RELIABLE:
case DCOMCT_UNORDERED_PARTIAL_RTXS:
case DCOMCT_UNORDERED_PARTIAL_TIME:
config->ordered = false;
}
config->maxRetransmits = -1;
config->maxRetransmitTime = -1;
switch (channel_type) {
case DCOMCT_ORDERED_PARTIAL_RTXS:
case DCOMCT_UNORDERED_PARTIAL_RTXS:
config->maxRetransmits = reliability_param;
break;
case DCOMCT_ORDERED_PARTIAL_TIME:
case DCOMCT_UNORDERED_PARTIAL_TIME:
config->maxRetransmitTime = reliability_param;
break;
}
return true;
}
bool ParseDataChannelOpenAckMessage(const rtc::Buffer& payload) {
rtc::ByteBuffer buffer(payload);
uint8_t message_type;
if (!buffer.ReadUInt8(&message_type)) {
LOG(LS_WARNING) << "Could not read OPEN_ACK message type.";
return false;
}
if (message_type != DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE) {
LOG(LS_WARNING) << "Data Channel OPEN_ACK message of unexpected type: "
<< message_type;
return false;
}
return true;
}
bool WriteDataChannelOpenMessage(const std::string& label,
const DataChannelInit& config,
rtc::Buffer* payload) {
// Format defined at
// http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-00#section-6.1
uint8_t channel_type = 0;
uint32_t reliability_param = 0;
uint16_t priority = 0;
if (config.ordered) {
if (config.maxRetransmits > -1) {
channel_type = DCOMCT_ORDERED_PARTIAL_RTXS;
reliability_param = config.maxRetransmits;
} else if (config.maxRetransmitTime > -1) {
channel_type = DCOMCT_ORDERED_PARTIAL_TIME;
reliability_param = config.maxRetransmitTime;
} else {
channel_type = DCOMCT_ORDERED_RELIABLE;
}
} else {
if (config.maxRetransmits > -1) {
channel_type = DCOMCT_UNORDERED_PARTIAL_RTXS;
reliability_param = config.maxRetransmits;
} else if (config.maxRetransmitTime > -1) {
channel_type = DCOMCT_UNORDERED_PARTIAL_TIME;
reliability_param = config.maxRetransmitTime;
} else {
channel_type = DCOMCT_UNORDERED_RELIABLE;
}
}
rtc::ByteBuffer buffer(
NULL, 20 + label.length() + config.protocol.length(),
rtc::ByteBuffer::ORDER_NETWORK);
buffer.WriteUInt8(DATA_CHANNEL_OPEN_MESSAGE_TYPE);
buffer.WriteUInt8(channel_type);
buffer.WriteUInt16(priority);
buffer.WriteUInt32(reliability_param);
buffer.WriteUInt16(static_cast<uint16_t>(label.length()));
buffer.WriteUInt16(static_cast<uint16_t>(config.protocol.length()));
buffer.WriteString(label);
buffer.WriteString(config.protocol);
payload->SetData(buffer.Data(), buffer.Length());
return true;
}
void WriteDataChannelOpenAckMessage(rtc::Buffer* payload) {
rtc::ByteBuffer buffer(rtc::ByteBuffer::ORDER_NETWORK);
buffer.WriteUInt8(DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE);
payload->SetData(buffer.Data(), buffer.Length());
}
} // namespace webrtc