rtc::Buffer: Rename length to size, for conformance with the STL

And add a constructor for creating an uninitialized Buffer of a
specified size.

(I intend to follow up with more Buffer changes, but since it's rather
widely used, the rename is quite noisy and works better as a separate
CL.)

R=tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/48579004

Cr-Commit-Position: refs/heads/master@{#8841}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8841 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
kwiberg@webrtc.org 2015-03-24 09:19:06 +00:00
parent e815290828
commit eebcab5ce9
33 changed files with 168 additions and 188 deletions

View File

@ -330,8 +330,8 @@ void DataChannel::OnDataReceived(cricket::DataChannel* channel,
if (was_ever_writable_ && observer_) { if (was_ever_writable_ && observer_) {
observer_->OnMessage(*buffer.get()); observer_->OnMessage(*buffer.get());
} else { } else {
if (queued_received_data_.byte_count() + payload.length() > if (queued_received_data_.byte_count() + payload.size() >
kMaxQueuedReceivedDataBytes) { kMaxQueuedReceivedDataBytes) {
LOG(LS_ERROR) << "Queued received data exceeds the max buffer size."; LOG(LS_ERROR) << "Queued received data exceeds the max buffer size.";
queued_received_data_.Clear(); queued_received_data_.Clear();

View File

@ -145,7 +145,7 @@ TEST_F(SctpDataChannelTest, BufferedAmountWhenBlocked) {
for (int i = 0; i < number_of_packets; ++i) { for (int i = 0; i < number_of_packets; ++i) {
EXPECT_TRUE(webrtc_data_channel_->Send(buffer)); EXPECT_TRUE(webrtc_data_channel_->Send(buffer));
} }
EXPECT_EQ(buffer.data.length() * number_of_packets, EXPECT_EQ(buffer.data.size() * number_of_packets,
webrtc_data_channel_->buffered_amount()); webrtc_data_channel_->buffered_amount());
} }
@ -359,10 +359,8 @@ TEST_F(SctpDataChannelTest, OpenAckRoleInitialization) {
TEST_F(SctpDataChannelTest, ClosedWhenSendBufferFull) { TEST_F(SctpDataChannelTest, ClosedWhenSendBufferFull) {
SetChannelReady(); SetChannelReady();
const size_t buffer_size = 1024; rtc::Buffer buffer(1024);
rtc::Buffer buffer; memset(buffer.data(), 0, buffer.size());
buffer.SetLength(buffer_size);
memset(buffer.data(), 0, buffer_size);
webrtc::DataBuffer packet(buffer, true); webrtc::DataBuffer packet(buffer, true);
provider_.set_send_blocked(true); provider_.set_send_blocked(true);
@ -413,10 +411,8 @@ TEST_F(SctpDataChannelTest, RemotePeerRequestClose) {
// Tests that the DataChannel is closed if the received buffer is full. // Tests that the DataChannel is closed if the received buffer is full.
TEST_F(SctpDataChannelTest, ClosedWhenReceivedBufferFull) { TEST_F(SctpDataChannelTest, ClosedWhenReceivedBufferFull) {
SetChannelReady(); SetChannelReady();
const size_t buffer_size = 1024; rtc::Buffer buffer(1024);
rtc::Buffer buffer; memset(buffer.data(), 0, buffer.size());
buffer.SetLength(buffer_size);
memset(buffer.data(), 0, buffer_size);
cricket::ReceiveDataParams params; cricket::ReceiveDataParams params;
params.ssrc = 0; params.ssrc = 0;

View File

@ -76,7 +76,7 @@ struct DataBuffer {
: data(text.data(), text.length()), : data(text.data(), text.length()),
binary(false) { binary(false) {
} }
size_t size() const { return data.length(); } size_t size() const { return data.size(); }
rtc::Buffer data; rtc::Buffer data;
// Indicates if the received data contains UTF-8 or binary data. // Indicates if the received data contains UTF-8 or binary data.

View File

@ -581,9 +581,8 @@ class DataChannelObserverWrapper : public DataChannelObserver {
void OnMessage(const DataBuffer& buffer) override { void OnMessage(const DataBuffer& buffer) override {
ScopedLocalRefFrame local_ref_frame(jni()); ScopedLocalRefFrame local_ref_frame(jni());
jobject byte_buffer = jobject byte_buffer = jni()->NewDirectByteBuffer(
jni()->NewDirectByteBuffer(const_cast<char*>(buffer.data.data()), const_cast<char*>(buffer.data.data()), buffer.data.size());
buffer.data.length());
jobject j_buffer = jni()->NewObject(*j_buffer_class_, j_buffer_ctor_, jobject j_buffer = jni()->NewObject(*j_buffer_class_, j_buffer_ctor_,
byte_buffer, buffer.binary); byte_buffer, buffer.binary);
jni()->CallVoidMethod(*j_observer_global_, j_on_message_mid_, j_buffer); jni()->CallVoidMethod(*j_observer_global_, j_on_message_mid_, j_buffer);

View File

@ -149,7 +149,7 @@ std::string StdStringFromNSString(NSString* nsString) {
- (NSData*)data { - (NSData*)data {
return [NSData dataWithBytes:_dataBuffer->data.data() return [NSData dataWithBytes:_dataBuffer->data.data()
length:_dataBuffer->data.length()]; length:_dataBuffer->data.size()];
} }
- (BOOL)isBinary { - (BOOL)isBinary {

View File

@ -54,7 +54,7 @@ bool ParseDataChannelOpenMessage(const rtc::Buffer& payload,
// Format defined at // Format defined at
// http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04 // http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04
rtc::ByteBuffer buffer(payload.data(), payload.length()); rtc::ByteBuffer buffer(payload.data(), payload.size());
uint8 message_type; uint8 message_type;
if (!buffer.ReadUInt8(&message_type)) { if (!buffer.ReadUInt8(&message_type)) {
@ -126,7 +126,7 @@ bool ParseDataChannelOpenMessage(const rtc::Buffer& payload,
} }
bool ParseDataChannelOpenAckMessage(const rtc::Buffer& payload) { bool ParseDataChannelOpenAckMessage(const rtc::Buffer& payload) {
rtc::ByteBuffer buffer(payload.data(), payload.length()); rtc::ByteBuffer buffer(payload.data(), payload.size());
uint8 message_type; uint8 message_type;
if (!buffer.ReadUInt8(&message_type)) { if (!buffer.ReadUInt8(&message_type)) {

View File

@ -538,8 +538,8 @@ StatsReport* StatsCollector::AddOneCertificateReport(
rtc::Buffer der_buffer; rtc::Buffer der_buffer;
cert->ToDER(&der_buffer); cert->ToDER(&der_buffer);
std::string der_base64; std::string der_base64;
rtc::Base64::EncodeFromArray( rtc::Base64::EncodeFromArray(der_buffer.data(), der_buffer.size(),
der_buffer.data(), der_buffer.length(), &der_base64); &der_base64);
StatsReport::Id id(StatsReport::NewTypedId( StatsReport::Id id(StatsReport::NewTypedId(
StatsReport::kStatsReportTypeCertificate, fingerprint)); StatsReport::kStatsReportTypeCertificate, fingerprint));

View File

@ -45,7 +45,7 @@ class FakeDataChannelProvider : public webrtc::DataChannelProviderInterface {
return false; return false;
} }
if (transport_error_ || payload.length() == 0) { if (transport_error_ || payload.size() == 0) {
*result = cricket::SDR_ERROR; *result = cricket::SDR_ERROR;
return false; return false;
} }

View File

@ -100,7 +100,7 @@ class MockDataChannelObserver : public webrtc::DataChannelObserver {
virtual void OnStateChange() { state_ = channel_->state(); } virtual void OnStateChange() { state_ = channel_->state(); }
virtual void OnMessage(const DataBuffer& buffer) { virtual void OnMessage(const DataBuffer& buffer) {
last_message_.assign(buffer.data.data(), buffer.data.length()); last_message_.assign(buffer.data.data(), buffer.data.size());
++received_message_count_; ++received_message_count_;
} }

View File

@ -193,11 +193,11 @@ template <class Base> class RtpHelper : public Base {
void set_playout(bool playout) { playout_ = playout; } void set_playout(bool playout) { playout_ = playout; }
virtual void OnPacketReceived(rtc::Buffer* packet, virtual void OnPacketReceived(rtc::Buffer* packet,
const rtc::PacketTime& packet_time) { const rtc::PacketTime& packet_time) {
rtp_packets_.push_back(std::string(packet->data(), packet->length())); rtp_packets_.push_back(std::string(packet->data(), packet->size()));
} }
virtual void OnRtcpReceived(rtc::Buffer* packet, virtual void OnRtcpReceived(rtc::Buffer* packet,
const rtc::PacketTime& packet_time) { const rtc::PacketTime& packet_time) {
rtcp_packets_.push_back(std::string(packet->data(), packet->length())); rtcp_packets_.push_back(std::string(packet->data(), packet->size()));
} }
virtual void OnReadyToSend(bool ready) { virtual void OnReadyToSend(bool ready) {
ready_to_send_ = ready; ready_to_send_ = ready;
@ -686,7 +686,7 @@ class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> {
return false; return false;
} else { } else {
last_sent_data_params_ = params; last_sent_data_params_ = params;
last_sent_data_ = std::string(payload.data(), payload.length()); last_sent_data_ = std::string(payload.data(), payload.size());
return true; return true;
} }
} }

View File

@ -71,7 +71,7 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
rtc::CritScope cs(&crit_); rtc::CritScope cs(&crit_);
int bytes = 0; int bytes = 0;
for (size_t i = 0; i < rtp_packets_.size(); ++i) { for (size_t i = 0; i < rtp_packets_.size(); ++i) {
bytes += static_cast<int>(rtp_packets_[i].length()); bytes += static_cast<int>(rtp_packets_[i].size());
} }
return bytes; return bytes;
} }
@ -138,7 +138,7 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
rtc::CritScope cs(&crit_); rtc::CritScope cs(&crit_);
uint32 cur_ssrc = 0; uint32 cur_ssrc = 0;
if (!GetRtpSsrc(packet->data(), packet->length(), &cur_ssrc)) { if (!GetRtpSsrc(packet->data(), packet->size(), &cur_ssrc)) {
return false; return false;
} }
sent_ssrcs_[cur_ssrc]++; sent_ssrcs_[cur_ssrc]++;
@ -156,7 +156,7 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
if (conf_) { if (conf_) {
rtc::Buffer buffer_copy(*packet); rtc::Buffer buffer_copy(*packet);
for (size_t i = 0; i < conf_sent_ssrcs_.size(); ++i) { for (size_t i = 0; i < conf_sent_ssrcs_.size(); ++i) {
if (!SetRtpSsrc(buffer_copy.data(), buffer_copy.length(), if (!SetRtpSsrc(buffer_copy.data(), buffer_copy.size(),
conf_sent_ssrcs_[i])) { conf_sent_ssrcs_[i])) {
return false; return false;
} }
@ -221,13 +221,13 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
} }
uint32 cur_ssrc = 0; uint32 cur_ssrc = 0;
for (size_t i = 0; i < rtp_packets_.size(); ++i) { for (size_t i = 0; i < rtp_packets_.size(); ++i) {
if (!GetRtpSsrc(rtp_packets_[i].data(), if (!GetRtpSsrc(rtp_packets_[i].data(), rtp_packets_[i].size(),
rtp_packets_[i].length(), &cur_ssrc)) { &cur_ssrc)) {
return; return;
} }
if (ssrc == cur_ssrc) { if (ssrc == cur_ssrc) {
if (bytes) { if (bytes) {
*bytes += static_cast<int>(rtp_packets_[i].length()); *bytes += static_cast<int>(rtp_packets_[i].size());
} }
if (packets) { if (packets) {
++(*packets); ++(*packets);

View File

@ -230,7 +230,7 @@ void RtpSenderReceiver::SetSendSsrc(uint32 ssrc) {
void RtpSenderReceiver::OnPacketReceived(rtc::Buffer* packet) { void RtpSenderReceiver::OnPacketReceived(rtc::Buffer* packet) {
if (rtp_dump_writer_) { if (rtp_dump_writer_) {
rtp_dump_writer_->WriteRtpPacket(packet->data(), packet->length()); rtp_dump_writer_->WriteRtpPacket(packet->data(), packet->size());
} }
} }

View File

@ -66,8 +66,8 @@ class FileNetworkInterface : public MediaChannel::NetworkInterface {
media_channel_->OnPacketReceived(packet, rtc::PacketTime()); media_channel_->OnPacketReceived(packet, rtc::PacketTime());
} }
if (dump_writer_.get() && if (dump_writer_.get() &&
rtc::SR_SUCCESS != dump_writer_->WriteRtpPacket( rtc::SR_SUCCESS !=
packet->data(), packet->length())) { dump_writer_->WriteRtpPacket(packet->data(), packet->size())) {
return false; return false;
} }

View File

@ -216,7 +216,7 @@ bool RtpDataMediaChannel::RemoveRecvStream(uint32 ssrc) {
void RtpDataMediaChannel::OnPacketReceived( void RtpDataMediaChannel::OnPacketReceived(
rtc::Buffer* packet, const rtc::PacketTime& packet_time) { rtc::Buffer* packet, const rtc::PacketTime& packet_time) {
RtpHeader header; RtpHeader header;
if (!GetRtpHeader(packet->data(), packet->length(), &header)) { if (!GetRtpHeader(packet->data(), packet->size(), &header)) {
// Don't want to log for every corrupt packet. // Don't want to log for every corrupt packet.
// LOG(LS_WARNING) << "Could not read rtp header from packet of length " // LOG(LS_WARNING) << "Could not read rtp header from packet of length "
// << packet->length() << "."; // << packet->length() << ".";
@ -224,7 +224,7 @@ void RtpDataMediaChannel::OnPacketReceived(
} }
size_t header_length; size_t header_length;
if (!GetRtpHeaderLen(packet->data(), packet->length(), &header_length)) { if (!GetRtpHeaderLen(packet->data(), packet->size(), &header_length)) {
// Don't want to log for every corrupt packet. // Don't want to log for every corrupt packet.
// LOG(LS_WARNING) << "Could not read rtp header" // LOG(LS_WARNING) << "Could not read rtp header"
// << length from packet of length " // << length from packet of length "
@ -232,7 +232,7 @@ void RtpDataMediaChannel::OnPacketReceived(
return; return;
} }
const char* data = packet->data() + header_length + sizeof(kReservedSpace); const char* data = packet->data() + header_length + sizeof(kReservedSpace);
size_t data_len = packet->length() - header_length - sizeof(kReservedSpace); size_t data_len = packet->size() - header_length - sizeof(kReservedSpace);
if (!receiving_) { if (!receiving_) {
LOG(LS_WARNING) << "Not receiving packet " LOG(LS_WARNING) << "Not receiving packet "
@ -292,7 +292,7 @@ bool RtpDataMediaChannel::SendData(
} }
if (!sending_) { if (!sending_) {
LOG(LS_WARNING) << "Not sending packet with ssrc=" << params.ssrc LOG(LS_WARNING) << "Not sending packet with ssrc=" << params.ssrc
<< " len=" << payload.length() << " before SetSend(true)."; << " len=" << payload.size() << " before SetSend(true).";
return false; return false;
} }
@ -316,8 +316,8 @@ bool RtpDataMediaChannel::SendData(
return false; return false;
} }
size_t packet_len = (kMinRtpPacketLen + sizeof(kReservedSpace) size_t packet_len = (kMinRtpPacketLen + sizeof(kReservedSpace) +
+ payload.length() + kMaxSrtpHmacOverhead); payload.size() + kMaxSrtpHmacOverhead);
if (packet_len > kDataMaxRtpPacketLen) { if (packet_len > kDataMaxRtpPacketLen) {
return false; return false;
} }
@ -339,19 +339,18 @@ bool RtpDataMediaChannel::SendData(
rtc::Buffer packet; rtc::Buffer packet;
packet.SetCapacity(packet_len); packet.SetCapacity(packet_len);
packet.SetLength(kMinRtpPacketLen); packet.SetSize(kMinRtpPacketLen);
if (!SetRtpHeader(packet.data(), packet.length(), header)) { if (!SetRtpHeader(packet.data(), packet.size(), header)) {
return false; return false;
} }
packet.AppendData(&kReservedSpace, sizeof(kReservedSpace)); packet.AppendData(&kReservedSpace, sizeof(kReservedSpace));
packet.AppendData(payload.data(), payload.length()); packet.AppendData(payload.data(), payload.size());
LOG(LS_VERBOSE) << "Sent RTP data packet: " LOG(LS_VERBOSE) << "Sent RTP data packet: "
<< " stream=" << found_stream->id << " stream=" << found_stream->id << " ssrc=" << header.ssrc
<< " ssrc=" << header.ssrc
<< ", seqnum=" << header.seq_num << ", seqnum=" << header.seq_num
<< ", timestamp=" << header.timestamp << ", timestamp=" << header.timestamp
<< ", len=" << payload.length(); << ", len=" << payload.size();
MediaChannel::SendPacket(&packet); MediaChannel::SendPacket(&packet);
send_limiter_->Use(packet_len, now); send_limiter_->Use(packet_len, now);

View File

@ -143,8 +143,8 @@ class RtpDataMediaChannelTest : public testing::Test {
// Assume RTP header of length 12 // Assume RTP header of length 12
rtc::scoped_ptr<const rtc::Buffer> packet( rtc::scoped_ptr<const rtc::Buffer> packet(
iface_->GetRtpPacket(index)); iface_->GetRtpPacket(index));
if (packet->length() > 12) { if (packet->size() > 12) {
return std::string(packet->data() + 12, packet->length() - 12); return std::string(packet->data() + 12, packet->size() - 12);
} else { } else {
return ""; return "";
} }
@ -154,7 +154,7 @@ class RtpDataMediaChannelTest : public testing::Test {
rtc::scoped_ptr<const rtc::Buffer> packet( rtc::scoped_ptr<const rtc::Buffer> packet(
iface_->GetRtpPacket(index)); iface_->GetRtpPacket(index));
cricket::RtpHeader header; cricket::RtpHeader header;
GetRtpHeader(packet->data(), packet->length(), &header); GetRtpHeader(packet->data(), packet->size(), &header);
return header; return header;
} }

View File

@ -670,7 +670,7 @@ class VideoMediaChannelTest : public testing::Test,
static bool ParseRtpPacket(const rtc::Buffer* p, bool* x, int* pt, static bool ParseRtpPacket(const rtc::Buffer* p, bool* x, int* pt,
int* seqnum, uint32* tstamp, uint32* ssrc, int* seqnum, uint32* tstamp, uint32* ssrc,
std::string* payload) { std::string* payload) {
rtc::ByteBuffer buf(p->data(), p->length()); rtc::ByteBuffer buf(p->data(), p->size());
uint8 u08 = 0; uint8 u08 = 0;
uint16 u16 = 0; uint16 u16 = 0;
uint32 u32 = 0; uint32 u32 = 0;
@ -730,10 +730,10 @@ class VideoMediaChannelTest : public testing::Test,
int count = 0; int count = 0;
for (int i = start_index; i < stop_index; ++i) { for (int i = start_index; i < stop_index; ++i) {
rtc::scoped_ptr<const rtc::Buffer> p(GetRtcpPacket(i)); rtc::scoped_ptr<const rtc::Buffer> p(GetRtcpPacket(i));
rtc::ByteBuffer buf(p->data(), p->length()); rtc::ByteBuffer buf(p->data(), p->size());
size_t total_len = 0; size_t total_len = 0;
// The packet may be a compound RTCP packet. // The packet may be a compound RTCP packet.
while (total_len < p->length()) { while (total_len < p->size()) {
// Read FMT, type and length. // Read FMT, type and length.
uint8 fmt = 0; uint8 fmt = 0;
uint8 type = 0; uint8 type = 0;

View File

@ -524,7 +524,7 @@ bool SctpDataMediaChannel::SendData(
if (!sending_) { if (!sending_) {
LOG(LS_WARNING) << debug_name_ << "->SendData(...): " LOG(LS_WARNING) << debug_name_ << "->SendData(...): "
<< "Not sending packet with ssrc=" << params.ssrc << "Not sending packet with ssrc=" << params.ssrc
<< " len=" << payload.length() << " before SetSend(true)."; << " len=" << payload.size() << " before SetSend(true).";
return false; return false;
} }
@ -560,11 +560,9 @@ bool SctpDataMediaChannel::SendData(
} }
// We don't fragment. // We don't fragment.
send_res = usrsctp_sendv(sock_, payload.data(), send_res = usrsctp_sendv(
static_cast<size_t>(payload.length()), sock_, payload.data(), static_cast<size_t>(payload.size()), NULL, 0, &spa,
NULL, 0, &spa, rtc::checked_cast<socklen_t>(sizeof(spa)), SCTP_SENDV_SPA, 0);
rtc::checked_cast<socklen_t>(sizeof(spa)),
SCTP_SENDV_SPA, 0);
if (send_res < 0) { if (send_res < 0) {
if (errno == SCTP_EWOULDBLOCK) { if (errno == SCTP_EWOULDBLOCK) {
*result = SDR_BLOCK; *result = SDR_BLOCK;
@ -586,8 +584,8 @@ bool SctpDataMediaChannel::SendData(
// Called by network interface when a packet has been received. // Called by network interface when a packet has been received.
void SctpDataMediaChannel::OnPacketReceived( void SctpDataMediaChannel::OnPacketReceived(
rtc::Buffer* packet, const rtc::PacketTime& packet_time) { rtc::Buffer* packet, const rtc::PacketTime& packet_time) {
LOG(LS_VERBOSE) << debug_name_ << "->OnPacketReceived(...): " << " length=" LOG(LS_VERBOSE) << debug_name_ << "->OnPacketReceived(...): "
<< packet->length() << ", sending: " << sending_; << " length=" << packet->size() << ", sending: " << sending_;
// Only give receiving packets to usrsctp after if connected. This enables two // Only give receiving packets to usrsctp after if connected. This enables two
// peers to each make a connect call, but for them not to receive an INIT // peers to each make a connect call, but for them not to receive an INIT
// packet before they have called connect; least the last receiver of the INIT // packet before they have called connect; least the last receiver of the INIT
@ -596,7 +594,7 @@ void SctpDataMediaChannel::OnPacketReceived(
// Pass received packet to SCTP stack. Once processed by usrsctp, the data // Pass received packet to SCTP stack. Once processed by usrsctp, the data
// will be will be given to the global OnSctpInboundData, and then, // will be will be given to the global OnSctpInboundData, and then,
// marshalled by a Post and handled with OnMessage. // marshalled by a Post and handled with OnMessage.
usrsctp_conninput(this, packet->data(), packet->length(), 0); usrsctp_conninput(this, packet->data(), packet->size(), 0);
} else { } else {
// TODO(ldixon): Consider caching the packet for very slightly better // TODO(ldixon): Consider caching the packet for very slightly better
// reliability. // reliability.
@ -609,10 +607,10 @@ void SctpDataMediaChannel::OnInboundPacketFromSctpToChannel(
<< "Received SCTP data:" << "Received SCTP data:"
<< " ssrc=" << packet->params.ssrc << " ssrc=" << packet->params.ssrc
<< " notification: " << (packet->flags & MSG_NOTIFICATION) << " notification: " << (packet->flags & MSG_NOTIFICATION)
<< " length=" << packet->buffer.length(); << " length=" << packet->buffer.size();
// Sending a packet with data == NULL (no data) is SCTPs "close the // Sending a packet with data == NULL (no data) is SCTPs "close the
// connection" message. This sets sock_ = NULL; // connection" message. This sets sock_ = NULL;
if (!packet->buffer.length() || !packet->buffer.data()) { if (!packet->buffer.size() || !packet->buffer.data()) {
LOG(LS_INFO) << debug_name_ << "->OnInboundPacketFromSctpToChannel(...): " LOG(LS_INFO) << debug_name_ << "->OnInboundPacketFromSctpToChannel(...): "
"No data, closing."; "No data, closing.";
return; return;
@ -628,16 +626,15 @@ void SctpDataMediaChannel::OnDataFromSctpToChannel(
const ReceiveDataParams& params, rtc::Buffer* buffer) { const ReceiveDataParams& params, rtc::Buffer* buffer) {
if (receiving_) { if (receiving_) {
LOG(LS_VERBOSE) << debug_name_ << "->OnDataFromSctpToChannel(...): " LOG(LS_VERBOSE) << debug_name_ << "->OnDataFromSctpToChannel(...): "
<< "Posting with length: " << buffer->length() << "Posting with length: " << buffer->size()
<< " on stream " << params.ssrc; << " on stream " << params.ssrc;
// Reports all received messages to upper layers, no matter whether the sid // Reports all received messages to upper layers, no matter whether the sid
// is known. // is known.
SignalDataReceived(params, buffer->data(), buffer->length()); SignalDataReceived(params, buffer->data(), buffer->size());
} else { } else {
LOG(LS_WARNING) << debug_name_ << "->OnDataFromSctpToChannel(...): " LOG(LS_WARNING) << debug_name_ << "->OnDataFromSctpToChannel(...): "
<< "Not receiving packet with sid=" << params.ssrc << "Not receiving packet with sid=" << params.ssrc
<< " len=" << buffer->length() << " len=" << buffer->size() << " before SetReceive(true).";
<< " before SetReceive(true).";
} }
} }
@ -697,7 +694,7 @@ bool SctpDataMediaChannel::ResetStream(uint32 ssrc) {
void SctpDataMediaChannel::OnNotificationFromSctp(rtc::Buffer* buffer) { void SctpDataMediaChannel::OnNotificationFromSctp(rtc::Buffer* buffer) {
const sctp_notification& notification = const sctp_notification& notification =
reinterpret_cast<const sctp_notification&>(*buffer->data()); reinterpret_cast<const sctp_notification&>(*buffer->data());
ASSERT(notification.sn_header.sn_length == buffer->length()); ASSERT(notification.sn_header.sn_length == buffer->size());
// TODO(ldixon): handle notifications appropriately. // TODO(ldixon): handle notifications appropriately.
switch (notification.sn_header.sn_type) { switch (notification.sn_header.sn_type) {
@ -891,7 +888,7 @@ bool SctpDataMediaChannel::SetRecvCodecs(const std::vector<DataCodec>& codecs) {
void SctpDataMediaChannel::OnPacketFromSctpToNetwork( void SctpDataMediaChannel::OnPacketFromSctpToNetwork(
rtc::Buffer* buffer) { rtc::Buffer* buffer) {
if (buffer->length() > kSctpMtu) { if (buffer->size() > kSctpMtu) {
LOG(LS_ERROR) << debug_name_ << "->OnPacketFromSctpToNetwork(...): " LOG(LS_ERROR) << debug_name_ << "->OnPacketFromSctpToNetwork(...): "
<< "SCTP seems to have made a packet that is bigger " << "SCTP seems to have made a packet that is bigger "
"than its official MTU."; "than its official MTU.";

View File

@ -74,7 +74,7 @@ class SctpFakeNetworkInterface : public cricket::MediaChannel::NetworkInterface,
// TODO(ldixon): Can/should we use Buffer.TransferTo here? // TODO(ldixon): Can/should we use Buffer.TransferTo here?
// Note: this assignment does a deep copy of data from packet. // Note: this assignment does a deep copy of data from packet.
rtc::Buffer* buffer = new rtc::Buffer(packet->data(), packet->length()); rtc::Buffer* buffer = new rtc::Buffer(packet->data(), packet->size());
thread_->Post(this, MSG_PACKET, rtc::WrapMessageData(buffer)); thread_->Post(this, MSG_PACKET, rtc::WrapMessageData(buffer));
LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::SendPacket, Posted message."; LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::SendPacket, Posted message.";
return true; return true;

View File

@ -2849,7 +2849,7 @@ void WebRtcVideoMediaChannel::OnPacketReceived(
// any multiplexed streams, just send it to the default channel. Otherwise, // any multiplexed streams, just send it to the default channel. Otherwise,
// send it to the specific decoder instance for that stream. // send it to the specific decoder instance for that stream.
uint32 ssrc = 0; uint32 ssrc = 0;
if (!GetRtpSsrc(packet->data(), packet->length(), &ssrc)) if (!GetRtpSsrc(packet->data(), packet->size(), &ssrc))
return; return;
int processing_channel_id = GetRecvChannelId(ssrc); int processing_channel_id = GetRecvChannelId(ssrc);
if (processing_channel_id == kChannelIdUnset) { if (processing_channel_id == kChannelIdUnset) {
@ -2865,9 +2865,7 @@ void WebRtcVideoMediaChannel::OnPacketReceived(
} }
engine()->vie()->network()->ReceivedRTPPacket( engine()->vie()->network()->ReceivedRTPPacket(
processing_channel_id, processing_channel_id, packet->data(), packet->size(),
packet->data(),
packet->length(),
webrtc::PacketTime(packet_time.timestamp, packet_time.not_before)); webrtc::PacketTime(packet_time.timestamp, packet_time.not_before));
} }
@ -2879,12 +2877,12 @@ void WebRtcVideoMediaChannel::OnRtcpReceived(
// correct receiver reports. // correct receiver reports.
uint32 ssrc = 0; uint32 ssrc = 0;
if (!GetRtcpSsrc(packet->data(), packet->length(), &ssrc)) { if (!GetRtcpSsrc(packet->data(), packet->size(), &ssrc)) {
LOG(LS_WARNING) << "Failed to parse SSRC from received RTCP packet"; LOG(LS_WARNING) << "Failed to parse SSRC from received RTCP packet";
return; return;
} }
int type = 0; int type = 0;
if (!GetRtcpType(packet->data(), packet->length(), &type)) { if (!GetRtcpType(packet->data(), packet->size(), &type)) {
LOG(LS_WARNING) << "Failed to parse type from received RTCP packet"; LOG(LS_WARNING) << "Failed to parse type from received RTCP packet";
return; return;
} }
@ -2894,9 +2892,7 @@ void WebRtcVideoMediaChannel::OnRtcpReceived(
int recv_channel_id = GetRecvChannelId(ssrc); int recv_channel_id = GetRecvChannelId(ssrc);
if (recv_channel_id != kChannelIdUnset && !IsDefaultChannelId(recv_channel_id)) { if (recv_channel_id != kChannelIdUnset && !IsDefaultChannelId(recv_channel_id)) {
engine_->vie()->network()->ReceivedRTCPPacket( engine_->vie()->network()->ReceivedRTCPPacket(
recv_channel_id, recv_channel_id, packet->data(), packet->size());
packet->data(),
packet->length());
} }
} }
// SR may continue RR and any RR entry may correspond to any one of the send // SR may continue RR and any RR entry may correspond to any one of the send
@ -2906,10 +2902,8 @@ void WebRtcVideoMediaChannel::OnRtcpReceived(
iter != send_channels_.end(); ++iter) { iter != send_channels_.end(); ++iter) {
WebRtcVideoChannelSendInfo* send_channel = iter->second; WebRtcVideoChannelSendInfo* send_channel = iter->second;
int channel_id = send_channel->channel_id(); int channel_id = send_channel->channel_id();
engine_->vie()->network()->ReceivedRTCPPacket( engine_->vie()->network()->ReceivedRTCPPacket(channel_id, packet->data(),
channel_id, packet->size());
packet->data(),
packet->length());
} }
} }

View File

@ -1105,7 +1105,7 @@ void WebRtcVideoChannel2::OnPacketReceived(
const rtc::PacketTime& packet_time) { const rtc::PacketTime& packet_time) {
const webrtc::PacketReceiver::DeliveryStatus delivery_result = const webrtc::PacketReceiver::DeliveryStatus delivery_result =
call_->Receiver()->DeliverPacket( call_->Receiver()->DeliverPacket(
reinterpret_cast<const uint8_t*>(packet->data()), packet->length()); reinterpret_cast<const uint8_t*>(packet->data()), packet->size());
switch (delivery_result) { switch (delivery_result) {
case webrtc::PacketReceiver::DELIVERY_OK: case webrtc::PacketReceiver::DELIVERY_OK:
return; return;
@ -1116,7 +1116,7 @@ void WebRtcVideoChannel2::OnPacketReceived(
} }
uint32 ssrc = 0; uint32 ssrc = 0;
if (!GetRtpSsrc(packet->data(), packet->length(), &ssrc)) { if (!GetRtpSsrc(packet->data(), packet->size(), &ssrc)) {
return; return;
} }
@ -1131,7 +1131,7 @@ void WebRtcVideoChannel2::OnPacketReceived(
} }
if (call_->Receiver()->DeliverPacket( if (call_->Receiver()->DeliverPacket(
reinterpret_cast<const uint8_t*>(packet->data()), packet->length()) != reinterpret_cast<const uint8_t*>(packet->data()), packet->size()) !=
webrtc::PacketReceiver::DELIVERY_OK) { webrtc::PacketReceiver::DELIVERY_OK) {
LOG(LS_WARNING) << "Failed to deliver RTP packet on re-delivery."; LOG(LS_WARNING) << "Failed to deliver RTP packet on re-delivery.";
return; return;
@ -1142,7 +1142,7 @@ void WebRtcVideoChannel2::OnRtcpReceived(
rtc::Buffer* packet, rtc::Buffer* packet,
const rtc::PacketTime& packet_time) { const rtc::PacketTime& packet_time) {
if (call_->Receiver()->DeliverPacket( if (call_->Receiver()->DeliverPacket(
reinterpret_cast<const uint8_t*>(packet->data()), packet->length()) != reinterpret_cast<const uint8_t*>(packet->data()), packet->size()) !=
webrtc::PacketReceiver::DELIVERY_OK) { webrtc::PacketReceiver::DELIVERY_OK) {
LOG(LS_WARNING) << "Failed to deliver RTCP packet."; LOG(LS_WARNING) << "Failed to deliver RTCP packet.";
} }

View File

@ -3107,8 +3107,8 @@ void WebRtcVoiceMediaChannel::OnPacketReceived(
// Pick which channel to send this packet to. If this packet doesn't match // Pick which channel to send this packet to. If this packet doesn't match
// any multiplexed streams, just send it to the default channel. Otherwise, // any multiplexed streams, just send it to the default channel. Otherwise,
// send it to the specific decoder instance for that stream. // send it to the specific decoder instance for that stream.
int which_channel = GetReceiveChannelNum( int which_channel =
ParseSsrc(packet->data(), packet->length(), false)); GetReceiveChannelNum(ParseSsrc(packet->data(), packet->size(), false));
if (which_channel == -1) { if (which_channel == -1) {
which_channel = voe_channel(); which_channel = voe_channel();
} }
@ -3131,9 +3131,7 @@ void WebRtcVoiceMediaChannel::OnPacketReceived(
// Pass it off to the decoder. // Pass it off to the decoder.
engine()->voe()->network()->ReceivedRTPPacket( engine()->voe()->network()->ReceivedRTPPacket(
which_channel, which_channel, packet->data(), packet->size(),
packet->data(),
packet->length(),
webrtc::PacketTime(packet_time.timestamp, packet_time.not_before)); webrtc::PacketTime(packet_time.timestamp, packet_time.not_before));
} }
@ -3144,7 +3142,7 @@ void WebRtcVoiceMediaChannel::OnRtcpReceived(
// Receiving channels need sender reports in order to create // Receiving channels need sender reports in order to create
// correct receiver reports. // correct receiver reports.
int type = 0; int type = 0;
if (!GetRtcpType(packet->data(), packet->length(), &type)) { if (!GetRtcpType(packet->data(), packet->size(), &type)) {
LOG(LS_WARNING) << "Failed to parse type from received RTCP packet"; LOG(LS_WARNING) << "Failed to parse type from received RTCP packet";
return; return;
} }
@ -3152,13 +3150,11 @@ void WebRtcVoiceMediaChannel::OnRtcpReceived(
// If it is a sender report, find the channel that is listening. // If it is a sender report, find the channel that is listening.
bool has_sent_to_default_channel = false; bool has_sent_to_default_channel = false;
if (type == kRtcpTypeSR) { if (type == kRtcpTypeSR) {
int which_channel = GetReceiveChannelNum( int which_channel =
ParseSsrc(packet->data(), packet->length(), true)); GetReceiveChannelNum(ParseSsrc(packet->data(), packet->size(), true));
if (which_channel != -1) { if (which_channel != -1) {
engine()->voe()->network()->ReceivedRTCPPacket( engine()->voe()->network()->ReceivedRTCPPacket(
which_channel, which_channel, packet->data(), packet->size());
packet->data(),
packet->length());
if (IsDefaultChannel(which_channel)) if (IsDefaultChannel(which_channel))
has_sent_to_default_channel = true; has_sent_to_default_channel = true;
@ -3176,9 +3172,7 @@ void WebRtcVoiceMediaChannel::OnRtcpReceived(
continue; continue;
engine()->voe()->network()->ReceivedRTCPPacket( engine()->voe()->network()->ReceivedRTCPPacket(
iter->second->channel(), iter->second->channel(), packet->data(), packet->size());
packet->data(),
packet->length());
} }
} }

View File

@ -131,8 +131,8 @@ static const char* PacketType(bool rtcp) {
static bool ValidPacket(bool rtcp, const rtc::Buffer* packet) { static bool ValidPacket(bool rtcp, const rtc::Buffer* packet) {
// Check the packet size. We could check the header too if needed. // Check the packet size. We could check the header too if needed.
return (packet && return (packet &&
packet->length() >= (!rtcp ? kMinRtpPacketLen : kMinRtcpPacketLen) && packet->size() >= (!rtcp ? kMinRtpPacketLen : kMinRtcpPacketLen) &&
packet->length() <= kMaxRtpPacketLen); packet->size() <= kMaxRtpPacketLen);
} }
static bool IsReceiveContentDirection(MediaContentDirection direction) { static bool IsReceiveContentDirection(MediaContentDirection direction) {
@ -497,15 +497,15 @@ bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet,
// Protect ourselves against crazy data. // Protect ourselves against crazy data.
if (!ValidPacket(rtcp, packet)) { if (!ValidPacket(rtcp, packet)) {
LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " "
<< PacketType(rtcp) << " packet: wrong size=" << PacketType(rtcp)
<< packet->length(); << " packet: wrong size=" << packet->size();
return false; return false;
} }
// Signal to the media sink before protecting the packet. // Signal to the media sink before protecting the packet.
{ {
rtc::CritScope cs(&signal_send_packet_cs_); rtc::CritScope cs(&signal_send_packet_cs_);
SignalSendPacketPreCrypto(packet->data(), packet->length(), rtcp); SignalSendPacketPreCrypto(packet->data(), packet->size(), rtcp);
} }
rtc::PacketOptions options(dscp); rtc::PacketOptions options(dscp);
@ -513,7 +513,7 @@ bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet,
if (srtp_filter_.IsActive()) { if (srtp_filter_.IsActive()) {
bool res; bool res;
char* data = packet->data(); char* data = packet->data();
int len = static_cast<int>(packet->length()); int len = static_cast<int>(packet->size());
if (!rtcp) { if (!rtcp) {
// If ENABLE_EXTERNAL_AUTH flag is on then packet authentication is not done // If ENABLE_EXTERNAL_AUTH flag is on then packet authentication is not done
// inside libsrtp for a RTP packet. A external HMAC module will be writing // inside libsrtp for a RTP packet. A external HMAC module will be writing
@ -566,7 +566,7 @@ bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet,
} }
// Update the length of the packet now that we've added the auth tag. // Update the length of the packet now that we've added the auth tag.
packet->SetLength(len); packet->SetSize(len);
} else if (secure_required_) { } else if (secure_required_) {
// This is a double check for something that supposedly can't happen. // This is a double check for something that supposedly can't happen.
LOG(LS_ERROR) << "Can't send outgoing " << PacketType(rtcp) LOG(LS_ERROR) << "Can't send outgoing " << PacketType(rtcp)
@ -579,13 +579,14 @@ bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet,
// Signal to the media sink after protecting the packet. // Signal to the media sink after protecting the packet.
{ {
rtc::CritScope cs(&signal_send_packet_cs_); rtc::CritScope cs(&signal_send_packet_cs_);
SignalSendPacketPostCrypto(packet->data(), packet->length(), rtcp); SignalSendPacketPostCrypto(packet->data(), packet->size(), rtcp);
} }
// Bon voyage. // Bon voyage.
int ret = channel->SendPacket(packet->data(), packet->length(), options, int ret =
(secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0); channel->SendPacket(packet->data(), packet->size(), options,
if (ret != static_cast<int>(packet->length())) { (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0);
if (ret != static_cast<int>(packet->size())) {
if (channel->GetError() == EWOULDBLOCK) { if (channel->GetError() == EWOULDBLOCK) {
LOG(LS_WARNING) << "Got EWOULDBLOCK from socket."; LOG(LS_WARNING) << "Got EWOULDBLOCK from socket.";
SetReadyToSend(channel, false); SetReadyToSend(channel, false);
@ -599,13 +600,13 @@ bool BaseChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) {
// Protect ourselves against crazy data. // Protect ourselves against crazy data.
if (!ValidPacket(rtcp, packet)) { if (!ValidPacket(rtcp, packet)) {
LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " "
<< PacketType(rtcp) << " packet: wrong size=" << PacketType(rtcp)
<< packet->length(); << " packet: wrong size=" << packet->size();
return false; return false;
} }
// Bundle filter handles both rtp and rtcp packets. // Bundle filter handles both rtp and rtcp packets.
return bundle_filter_.DemuxPacket(packet->data(), packet->length(), rtcp); return bundle_filter_.DemuxPacket(packet->data(), packet->size(), rtcp);
} }
void BaseChannel::HandlePacket(bool rtcp, rtc::Buffer* packet, void BaseChannel::HandlePacket(bool rtcp, rtc::Buffer* packet,
@ -624,13 +625,13 @@ void BaseChannel::HandlePacket(bool rtcp, rtc::Buffer* packet,
// Signal to the media sink before unprotecting the packet. // Signal to the media sink before unprotecting the packet.
{ {
rtc::CritScope cs(&signal_recv_packet_cs_); rtc::CritScope cs(&signal_recv_packet_cs_);
SignalRecvPacketPostCrypto(packet->data(), packet->length(), rtcp); SignalRecvPacketPostCrypto(packet->data(), packet->size(), rtcp);
} }
// Unprotect the packet, if needed. // Unprotect the packet, if needed.
if (srtp_filter_.IsActive()) { if (srtp_filter_.IsActive()) {
char* data = packet->data(); char* data = packet->data();
int len = static_cast<int>(packet->length()); int len = static_cast<int>(packet->size());
bool res; bool res;
if (!rtcp) { if (!rtcp) {
res = srtp_filter_.UnprotectRtp(data, len, &len); res = srtp_filter_.UnprotectRtp(data, len, &len);
@ -655,7 +656,7 @@ void BaseChannel::HandlePacket(bool rtcp, rtc::Buffer* packet,
} }
} }
packet->SetLength(len); packet->SetSize(len);
} else if (secure_required_) { } else if (secure_required_) {
// Our session description indicates that SRTP is required, but we got a // Our session description indicates that SRTP is required, but we got a
// packet before our SRTP filter is active. This means either that // packet before our SRTP filter is active. This means either that
@ -675,7 +676,7 @@ void BaseChannel::HandlePacket(bool rtcp, rtc::Buffer* packet,
// Signal to the media sink after unprotecting the packet. // Signal to the media sink after unprotecting the packet.
{ {
rtc::CritScope cs(&signal_recv_packet_cs_); rtc::CritScope cs(&signal_recv_packet_cs_);
SignalRecvPacketPreCrypto(packet->data(), packet->length(), rtcp); SignalRecvPacketPreCrypto(packet->data(), packet->size(), rtcp);
} }
// Push it down to the media channel. // Push it down to the media channel.
@ -2213,7 +2214,7 @@ bool DataChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) {
if (data_channel_type_ == DCT_SCTP) { if (data_channel_type_ == DCT_SCTP) {
// TODO(pthatcher): Do this in a more robust way by checking for // TODO(pthatcher): Do this in a more robust way by checking for
// SCTP or DTLS. // SCTP or DTLS.
return !IsRtpPacket(packet->data(), packet->length()); return !IsRtpPacket(packet->data(), packet->size());
} else if (data_channel_type_ == DCT_RTP) { } else if (data_channel_type_ == DCT_RTP) {
return BaseChannel::WantsPacket(rtcp, packet); return BaseChannel::WantsPacket(rtcp, packet);
} }

View File

@ -16,16 +16,20 @@ Buffer::Buffer() {
Construct(NULL, 0, 0); Construct(NULL, 0, 0);
} }
Buffer::Buffer(const void* data, size_t length) { Buffer::Buffer(size_t size) : Buffer() {
Construct(data, length, length); SetSize(size);
} }
Buffer::Buffer(const void* data, size_t length, size_t capacity) { Buffer::Buffer(const void* data, size_t size) {
Construct(data, length, capacity); Construct(data, size, size);
}
Buffer::Buffer(const void* data, size_t size, size_t capacity) {
Construct(data, size, capacity);
} }
Buffer::Buffer(const Buffer& buf) { Buffer::Buffer(const Buffer& buf) {
Construct(buf.data(), buf.length(), buf.length()); Construct(buf.data(), buf.size(), buf.size());
} }
Buffer::~Buffer() = default; Buffer::~Buffer() = default;

View File

@ -23,50 +23,49 @@ namespace rtc {
class Buffer { class Buffer {
public: public:
Buffer(); Buffer();
Buffer(const void* data, size_t length); explicit Buffer(size_t size);
Buffer(const void* data, size_t length, size_t capacity); Buffer(const void* data, size_t size);
Buffer(const void* data, size_t size, size_t capacity);
Buffer(const Buffer& buf); Buffer(const Buffer& buf);
~Buffer(); ~Buffer();
const char* data() const { return data_.get(); } const char* data() const { return data_.get(); }
char* data() { return data_.get(); } char* data() { return data_.get(); }
// TODO: should this be size(), like STL? size_t size() const { return size_; }
size_t length() const { return length_; }
size_t capacity() const { return capacity_; } size_t capacity() const { return capacity_; }
Buffer& operator=(const Buffer& buf) { Buffer& operator=(const Buffer& buf) {
if (&buf != this) { if (&buf != this) {
Construct(buf.data(), buf.length(), buf.length()); Construct(buf.data(), buf.size(), buf.size());
} }
return *this; return *this;
} }
bool operator==(const Buffer& buf) const { bool operator==(const Buffer& buf) const {
return (length_ == buf.length() && return (size_ == buf.size() && memcmp(data_.get(), buf.data(), size_) == 0);
memcmp(data_.get(), buf.data(), length_) == 0);
} }
bool operator!=(const Buffer& buf) const { bool operator!=(const Buffer& buf) const {
return !operator==(buf); return !operator==(buf);
} }
void SetData(const void* data, size_t length) { void SetData(const void* data, size_t size) {
ASSERT(data != NULL || length == 0); ASSERT(data != NULL || size == 0);
SetLength(length); SetSize(size);
memcpy(data_.get(), data, length); memcpy(data_.get(), data, size);
} }
void AppendData(const void* data, size_t length) { void AppendData(const void* data, size_t size) {
ASSERT(data != NULL || length == 0); ASSERT(data != NULL || size == 0);
size_t old_length = length_; size_t old_size = size_;
SetLength(length_ + length); SetSize(size_ + size);
memcpy(data_.get() + old_length, data, length); memcpy(data_.get() + old_size, data, size);
} }
void SetLength(size_t length) { void SetSize(size_t size) {
SetCapacity(length); SetCapacity(size);
length_ = length; size_ = size;
} }
void SetCapacity(size_t capacity) { void SetCapacity(size_t capacity) {
if (capacity > capacity_) { if (capacity > capacity_) {
rtc::scoped_ptr<char[]> data(new char[capacity]); rtc::scoped_ptr<char[]> data(new char[capacity]);
memcpy(data.get(), data_.get(), length_); memcpy(data.get(), data_.get(), size_);
data_.swap(data); data_.swap(data);
capacity_ = capacity; capacity_ = capacity;
} }
@ -75,19 +74,19 @@ class Buffer {
void TransferTo(Buffer* buf) { void TransferTo(Buffer* buf) {
ASSERT(buf != NULL); ASSERT(buf != NULL);
buf->data_.reset(data_.release()); buf->data_.reset(data_.release());
buf->length_ = length_; buf->size_ = size_;
buf->capacity_ = capacity_; buf->capacity_ = capacity_;
Construct(NULL, 0, 0); Construct(NULL, 0, 0);
} }
protected: protected:
void Construct(const void* data, size_t length, size_t capacity) { void Construct(const void* data, size_t size, size_t capacity) {
data_.reset(new char[capacity_ = capacity]); data_.reset(new char[capacity_ = capacity]);
SetData(data, length); SetData(data, size);
} }
scoped_ptr<char[]> data_; scoped_ptr<char[]> data_;
size_t length_; size_t size_;
size_t capacity_; size_t capacity_;
}; };

View File

@ -19,21 +19,21 @@ static const char kTestData[] = {
TEST(BufferTest, TestConstructDefault) { TEST(BufferTest, TestConstructDefault) {
Buffer buf; Buffer buf;
EXPECT_EQ(0U, buf.length()); EXPECT_EQ(0U, buf.size());
EXPECT_EQ(0U, buf.capacity()); EXPECT_EQ(0U, buf.capacity());
EXPECT_EQ(Buffer(), buf); EXPECT_EQ(Buffer(), buf);
} }
TEST(BufferTest, TestConstructEmptyWithCapacity) { TEST(BufferTest, TestConstructEmptyWithCapacity) {
Buffer buf(NULL, 0, 256U); Buffer buf(NULL, 0, 256U);
EXPECT_EQ(0U, buf.length()); EXPECT_EQ(0U, buf.size());
EXPECT_EQ(256U, buf.capacity()); EXPECT_EQ(256U, buf.capacity());
EXPECT_EQ(Buffer(), buf); EXPECT_EQ(Buffer(), buf);
} }
TEST(BufferTest, TestConstructData) { TEST(BufferTest, TestConstructData) {
Buffer buf(kTestData, sizeof(kTestData)); Buffer buf(kTestData, sizeof(kTestData));
EXPECT_EQ(sizeof(kTestData), buf.length()); EXPECT_EQ(sizeof(kTestData), buf.size());
EXPECT_EQ(sizeof(kTestData), buf.capacity()); EXPECT_EQ(sizeof(kTestData), buf.capacity());
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData))); EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
EXPECT_EQ(Buffer(kTestData, sizeof(kTestData)), buf); EXPECT_EQ(Buffer(kTestData, sizeof(kTestData)), buf);
@ -41,7 +41,7 @@ TEST(BufferTest, TestConstructData) {
TEST(BufferTest, TestConstructDataWithCapacity) { TEST(BufferTest, TestConstructDataWithCapacity) {
Buffer buf(kTestData, sizeof(kTestData), 256U); Buffer buf(kTestData, sizeof(kTestData), 256U);
EXPECT_EQ(sizeof(kTestData), buf.length()); EXPECT_EQ(sizeof(kTestData), buf.size());
EXPECT_EQ(256U, buf.capacity()); EXPECT_EQ(256U, buf.capacity());
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData))); EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
EXPECT_EQ(Buffer(kTestData, sizeof(kTestData)), buf); EXPECT_EQ(Buffer(kTestData, sizeof(kTestData)), buf);
@ -49,7 +49,7 @@ TEST(BufferTest, TestConstructDataWithCapacity) {
TEST(BufferTest, TestConstructCopy) { TEST(BufferTest, TestConstructCopy) {
Buffer buf1(kTestData, sizeof(kTestData), 256), buf2(buf1); Buffer buf1(kTestData, sizeof(kTestData), 256), buf2(buf1);
EXPECT_EQ(sizeof(kTestData), buf2.length()); EXPECT_EQ(sizeof(kTestData), buf2.size());
EXPECT_EQ(sizeof(kTestData), buf2.capacity()); // capacity isn't copied EXPECT_EQ(sizeof(kTestData), buf2.capacity()); // capacity isn't copied
EXPECT_EQ(0, memcmp(buf2.data(), kTestData, sizeof(kTestData))); EXPECT_EQ(0, memcmp(buf2.data(), kTestData, sizeof(kTestData)));
EXPECT_EQ(buf1, buf2); EXPECT_EQ(buf1, buf2);
@ -59,7 +59,7 @@ TEST(BufferTest, TestAssign) {
Buffer buf1, buf2(kTestData, sizeof(kTestData), 256); Buffer buf1, buf2(kTestData, sizeof(kTestData), 256);
EXPECT_NE(buf1, buf2); EXPECT_NE(buf1, buf2);
buf1 = buf2; buf1 = buf2;
EXPECT_EQ(sizeof(kTestData), buf1.length()); EXPECT_EQ(sizeof(kTestData), buf1.size());
EXPECT_EQ(sizeof(kTestData), buf1.capacity()); // capacity isn't copied EXPECT_EQ(sizeof(kTestData), buf1.capacity()); // capacity isn't copied
EXPECT_EQ(0, memcmp(buf1.data(), kTestData, sizeof(kTestData))); EXPECT_EQ(0, memcmp(buf1.data(), kTestData, sizeof(kTestData)));
EXPECT_EQ(buf1, buf2); EXPECT_EQ(buf1, buf2);
@ -68,7 +68,7 @@ TEST(BufferTest, TestAssign) {
TEST(BufferTest, TestSetData) { TEST(BufferTest, TestSetData) {
Buffer buf; Buffer buf;
buf.SetData(kTestData, sizeof(kTestData)); buf.SetData(kTestData, sizeof(kTestData));
EXPECT_EQ(sizeof(kTestData), buf.length()); EXPECT_EQ(sizeof(kTestData), buf.size());
EXPECT_EQ(sizeof(kTestData), buf.capacity()); EXPECT_EQ(sizeof(kTestData), buf.capacity());
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData))); EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
} }
@ -76,27 +76,27 @@ TEST(BufferTest, TestSetData) {
TEST(BufferTest, TestAppendData) { TEST(BufferTest, TestAppendData) {
Buffer buf(kTestData, sizeof(kTestData)); Buffer buf(kTestData, sizeof(kTestData));
buf.AppendData(kTestData, sizeof(kTestData)); buf.AppendData(kTestData, sizeof(kTestData));
EXPECT_EQ(2 * sizeof(kTestData), buf.length()); EXPECT_EQ(2 * sizeof(kTestData), buf.size());
EXPECT_EQ(2 * sizeof(kTestData), buf.capacity()); EXPECT_EQ(2 * sizeof(kTestData), buf.capacity());
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData))); EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
EXPECT_EQ(0, memcmp(buf.data() + sizeof(kTestData), EXPECT_EQ(0, memcmp(buf.data() + sizeof(kTestData),
kTestData, sizeof(kTestData))); kTestData, sizeof(kTestData)));
} }
TEST(BufferTest, TestSetLengthSmaller) { TEST(BufferTest, TestSetSizeSmaller) {
Buffer buf; Buffer buf;
buf.SetData(kTestData, sizeof(kTestData)); buf.SetData(kTestData, sizeof(kTestData));
buf.SetLength(sizeof(kTestData) / 2); buf.SetSize(sizeof(kTestData) / 2);
EXPECT_EQ(sizeof(kTestData) / 2, buf.length()); EXPECT_EQ(sizeof(kTestData) / 2, buf.size());
EXPECT_EQ(sizeof(kTestData), buf.capacity()); EXPECT_EQ(sizeof(kTestData), buf.capacity());
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData) / 2)); EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData) / 2));
} }
TEST(BufferTest, TestSetLengthLarger) { TEST(BufferTest, TestSetSizeLarger) {
Buffer buf; Buffer buf;
buf.SetData(kTestData, sizeof(kTestData)); buf.SetData(kTestData, sizeof(kTestData));
buf.SetLength(sizeof(kTestData) * 2); buf.SetSize(sizeof(kTestData) * 2);
EXPECT_EQ(sizeof(kTestData) * 2, buf.length()); EXPECT_EQ(sizeof(kTestData) * 2, buf.size());
EXPECT_EQ(sizeof(kTestData) * 2, buf.capacity()); EXPECT_EQ(sizeof(kTestData) * 2, buf.capacity());
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData))); EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
} }
@ -105,7 +105,7 @@ TEST(BufferTest, TestSetCapacitySmaller) {
Buffer buf; Buffer buf;
buf.SetData(kTestData, sizeof(kTestData)); buf.SetData(kTestData, sizeof(kTestData));
buf.SetCapacity(sizeof(kTestData) / 2); // should be ignored buf.SetCapacity(sizeof(kTestData) / 2); // should be ignored
EXPECT_EQ(sizeof(kTestData), buf.length()); EXPECT_EQ(sizeof(kTestData), buf.size());
EXPECT_EQ(sizeof(kTestData), buf.capacity()); EXPECT_EQ(sizeof(kTestData), buf.capacity());
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData))); EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
} }
@ -113,17 +113,17 @@ TEST(BufferTest, TestSetCapacitySmaller) {
TEST(BufferTest, TestSetCapacityLarger) { TEST(BufferTest, TestSetCapacityLarger) {
Buffer buf(kTestData, sizeof(kTestData)); Buffer buf(kTestData, sizeof(kTestData));
buf.SetCapacity(sizeof(kTestData) * 2); buf.SetCapacity(sizeof(kTestData) * 2);
EXPECT_EQ(sizeof(kTestData), buf.length()); EXPECT_EQ(sizeof(kTestData), buf.size());
EXPECT_EQ(sizeof(kTestData) * 2, buf.capacity()); EXPECT_EQ(sizeof(kTestData) * 2, buf.capacity());
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData))); EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
} }
TEST(BufferTest, TestSetCapacityThenSetLength) { TEST(BufferTest, TestSetCapacityThenSetSize) {
Buffer buf(kTestData, sizeof(kTestData)); Buffer buf(kTestData, sizeof(kTestData));
buf.SetCapacity(sizeof(kTestData) * 4); buf.SetCapacity(sizeof(kTestData) * 4);
memcpy(buf.data() + sizeof(kTestData), kTestData, sizeof(kTestData)); memcpy(buf.data() + sizeof(kTestData), kTestData, sizeof(kTestData));
buf.SetLength(sizeof(kTestData) * 2); buf.SetSize(sizeof(kTestData) * 2);
EXPECT_EQ(sizeof(kTestData) * 2, buf.length()); EXPECT_EQ(sizeof(kTestData) * 2, buf.size());
EXPECT_EQ(sizeof(kTestData) * 4, buf.capacity()); EXPECT_EQ(sizeof(kTestData) * 4, buf.capacity());
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData))); EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
EXPECT_EQ(0, memcmp(buf.data() + sizeof(kTestData), EXPECT_EQ(0, memcmp(buf.data() + sizeof(kTestData),
@ -133,9 +133,9 @@ TEST(BufferTest, TestSetCapacityThenSetLength) {
TEST(BufferTest, TestTransfer) { TEST(BufferTest, TestTransfer) {
Buffer buf1(kTestData, sizeof(kTestData), 256U), buf2; Buffer buf1(kTestData, sizeof(kTestData), 256U), buf2;
buf1.TransferTo(&buf2); buf1.TransferTo(&buf2);
EXPECT_EQ(0U, buf1.length()); EXPECT_EQ(0U, buf1.size());
EXPECT_EQ(0U, buf1.capacity()); EXPECT_EQ(0U, buf1.capacity());
EXPECT_EQ(sizeof(kTestData), buf2.length()); EXPECT_EQ(sizeof(kTestData), buf2.size());
EXPECT_EQ(256U, buf2.capacity()); // capacity does transfer EXPECT_EQ(256U, buf2.capacity()); // capacity does transfer
EXPECT_EQ(0, memcmp(buf2.data(), kTestData, sizeof(kTestData))); EXPECT_EQ(0, memcmp(buf2.data(), kTestData, sizeof(kTestData)));
} }

View File

@ -79,8 +79,7 @@ bool SSLFingerprint::operator==(const SSLFingerprint& other) const {
std::string SSLFingerprint::GetRfc4572Fingerprint() const { std::string SSLFingerprint::GetRfc4572Fingerprint() const {
std::string fingerprint = std::string fingerprint =
rtc::hex_encode_with_delimiter( rtc::hex_encode_with_delimiter(digest.data(), digest.size(), ':');
digest.data(), digest.length(), ':');
std::transform(fingerprint.begin(), fingerprint.end(), std::transform(fingerprint.begin(), fingerprint.end(),
fingerprint.begin(), ::toupper); fingerprint.begin(), ::toupper);
return fingerprint; return fingerprint;

View File

@ -754,7 +754,7 @@ StreamResult AsyncWriteStream::Write(const void* data, size_t data_len,
size_t previous_buffer_length = 0; size_t previous_buffer_length = 0;
{ {
CritScope cs(&crit_buffer_); CritScope cs(&crit_buffer_);
previous_buffer_length = buffer_.length(); previous_buffer_length = buffer_.size();
buffer_.AppendData(data, data_len); buffer_.AppendData(data, data_len);
} }
@ -793,9 +793,9 @@ void AsyncWriteStream::ClearBufferAndWrite() {
buffer_.TransferTo(&to_write); buffer_.TransferTo(&to_write);
} }
if (to_write.length() > 0) { if (to_write.size() > 0) {
CritScope cs(&crit_stream_); CritScope cs(&crit_stream_);
stream_->WriteAll(to_write.data(), to_write.length(), NULL, NULL); stream_->WriteAll(to_write.data(), to_write.size(), NULL, NULL);
} }
} }

View File

@ -1354,13 +1354,13 @@ TEST_F(RtpSenderVideoTest, SendVideoWithCVO) {
// Verify that this packet doesn't have CVO byte. // Verify that this packet doesn't have CVO byte.
VerifyCVOPacket( VerifyCVOPacket(
reinterpret_cast<uint8_t*>(transport_.sent_packets_[0]->data()), reinterpret_cast<uint8_t*>(transport_.sent_packets_[0]->data()),
transport_.sent_packets_[0]->length(), false, &map, kSeqNum, transport_.sent_packets_[0]->size(), false, &map, kSeqNum,
kVideoRotation_0); kVideoRotation_0);
// Verify that this packet doesn't have CVO byte. // Verify that this packet doesn't have CVO byte.
VerifyCVOPacket( VerifyCVOPacket(
reinterpret_cast<uint8_t*>(transport_.sent_packets_[1]->data()), reinterpret_cast<uint8_t*>(transport_.sent_packets_[1]->data()),
transport_.sent_packets_[1]->length(), true, &map, kSeqNum + 1, transport_.sent_packets_[1]->size(), true, &map, kSeqNum + 1,
hdr.rotation); hdr.rotation);
} }
} // namespace webrtc } // namespace webrtc

View File

@ -220,10 +220,9 @@ class DtlsTransport : public Base {
} }
// Apply remote fingerprint. // Apply remote fingerprint.
if (!channel->SetRemoteFingerprint( if (!channel->SetRemoteFingerprint(
remote_fingerprint_->algorithm, remote_fingerprint_->algorithm,
reinterpret_cast<const uint8 *>(remote_fingerprint_-> reinterpret_cast<const uint8*>(remote_fingerprint_->digest.data()),
digest.data()), remote_fingerprint_->digest.size())) {
remote_fingerprint_->digest.length())) {
return BadTransportDescription("Failed to apply remote fingerprint.", return BadTransportDescription("Failed to apply remote fingerprint.",
error_desc); error_desc);
} }

View File

@ -263,8 +263,8 @@ bool DtlsTransportChannelWrapper::SetupDtls() {
dtls_->SignalEvent.connect(this, &DtlsTransportChannelWrapper::OnDtlsEvent); dtls_->SignalEvent.connect(this, &DtlsTransportChannelWrapper::OnDtlsEvent);
if (!dtls_->SetPeerCertificateDigest( if (!dtls_->SetPeerCertificateDigest(
remote_fingerprint_algorithm_, remote_fingerprint_algorithm_,
reinterpret_cast<unsigned char *>(remote_fingerprint_value_.data()), reinterpret_cast<unsigned char*>(remote_fingerprint_value_.data()),
remote_fingerprint_value_.length())) { remote_fingerprint_value_.size())) {
LOG_J(LS_ERROR, this) << "Couldn't set DTLS certificate digest."; LOG_J(LS_ERROR, this) << "Couldn't set DTLS certificate digest.";
return false; return false;
} }

View File

@ -213,8 +213,7 @@ class FakeTransportChannel : public TransportChannelImpl,
virtual void OnMessage(rtc::Message* msg) { virtual void OnMessage(rtc::Message* msg) {
PacketMessageData* data = static_cast<PacketMessageData*>( PacketMessageData* data = static_cast<PacketMessageData*>(
msg->pdata); msg->pdata);
dest_->SignalReadPacket(dest_, data->packet.data(), dest_->SignalReadPacket(dest_, data->packet.data(), data->packet.size(),
data->packet.length(),
rtc::CreatePacketTime(0), 0); rtc::CreatePacketTime(0), 0);
delete data; delete data;
} }

View File

@ -50,7 +50,7 @@ class TransportDescriptionFactoryTest : public testing::Test {
} else { } else {
ASSERT_TRUE(desc->identity_fingerprint.get() != NULL); ASSERT_TRUE(desc->identity_fingerprint.get() != NULL);
EXPECT_EQ(desc->identity_fingerprint->algorithm, dtls_alg); EXPECT_EQ(desc->identity_fingerprint->algorithm, dtls_alg);
EXPECT_GT(desc->identity_fingerprint->digest.length(), 0U); EXPECT_GT(desc->identity_fingerprint->digest.size(), 0U);
} }
} }

View File

@ -437,8 +437,8 @@ class TurnPortTest : public testing::Test,
ASSERT_EQ_WAIT(num_packets, turn_packets_.size(), kTimeout); ASSERT_EQ_WAIT(num_packets, turn_packets_.size(), kTimeout);
ASSERT_EQ_WAIT(num_packets, udp_packets_.size(), kTimeout); ASSERT_EQ_WAIT(num_packets, udp_packets_.size(), kTimeout);
for (size_t i = 0; i < num_packets; ++i) { for (size_t i = 0; i < num_packets; ++i) {
EXPECT_EQ(i + 1, turn_packets_[i].length()); EXPECT_EQ(i + 1, turn_packets_[i].size());
EXPECT_EQ(i + 1, udp_packets_[i].length()); EXPECT_EQ(i + 1, udp_packets_[i].size());
EXPECT_EQ(turn_packets_[i], udp_packets_[i]); EXPECT_EQ(turn_packets_[i], udp_packets_[i]);
} }
} }